Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Compiler Error Message: CS0103 in MVC app (The name 'Html' does not exist in the current context)

Posted on 2011-02-27
4
Medium Priority
?
2,890 Views
Last Modified: 2013-11-08
Please look at this sample code and my question followed:

<%@ Page Title="" Language="C#" 
MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<% Html.RenderPartial("~/Views/Shared/Message.ascx"); %>
<form method="post" action="<%= Url.Action(this.ViewContext.RouteData.Values["action"] as string, "Article") %>" class="article-create">
		
	<h3>Article</h3>
	<p><label for="categoryId">Category</label><br />
                     <%= Html.DropDownList("categoryId")%></p>		
	<p><label for="title">Title</label><br />
	<%= Html.TextBox("title", ViewData["title"], new { @maxlength = 256 })%>
</form>
</asp:Content>

Open in new window


When I move my mouse over to one of the Html's it says:

HtmlHelper.ViewPage.Html
Returns a System.Web.Mvc.HtmlHelper contains methods useful for rendering html elements.


However, I've gotten this CS0103 on a page with a slightly different Inherits attribute

<%@ Page Language="C#" 
MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<IEnumerable<MyApplicationProject.Models.Category>>" %>

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
<div id="categories">
<% foreach (Category category in ViewData.Model) { %>
	<div class="admin">
		<%= Html.ActionLink("Edit", "EditCategory", new { controller = "Article", categoryId = category.CategoryID })%>&nbsp;|&nbsp;
		<%= Html.ActionLink("Remove", "RemoveCategory", new { controller = "Article", categoryId = category.CategoryID })%>
	</div>
	<% Html.RenderPartial("~/Views/Shared/Article/CategoryItem.ascx", category); %>
	<hr />
<% } %>
</div>
</asp:Content>

Open in new window


What wrong is that all the 'Html''s are underlined in red in my VS2008.
So I wanted to see what would happen when I remove <IEnumerable<MyApplicationProject.Models.Category>> I noticed the index obj (Category) in my loop remain underlined in red whether I remove the IEnumerable portion of the inherits attribute or not - but that's a different issue (i.e. The type or namespace name 'Category' could not be found (are you missing a using directive or an assembly reference?) However, all the Html's were no longer underlined (I supposed the errors were gone in this case)

For now, I wonder how I  go about to fix the html errors with the <IEnumerable<MyApplicationProject.Models.Category>> intact for my loop. My entired project compiles OK regardless, but when it comes to individual page as I open it in VS2008, all those html's got underlined in red; and it says 'The name html does not exist in the current context' on mouse over (don't even need to run it to see the CS0103 Compiler error, arg it is so frustrating to look at them)  (Are these complile errors only fixed at run-time or something? I think I've got MyApplicationProject.Models referenced. Thank you for reading.)

BTW I supplied the namespace for the Category as shown (MyApplicationProject.Models) but the error woudln't go away. What else do I miss?
0
Comment
Question by:MercuryKT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
jmcmunn earned 750 total points
ID: 34996626

It seems to be a namespace conflict.  Have you tried using the fully qualified namespace for for Html when you have your typed view?

System.Web.Mvc.Html

If that works, it indicates that somehow you have created a namespace conflict in your own code files.
0
 
LVL 10

Assisted Solution

by:pramodsk40
pramodsk40 earned 750 total points
ID: 34997938
0
 

Author Comment

by:MercuryKT
ID: 35044816
yes, I did got the namespace conflict  error message. I tried both, that and System.Web.Mvc.HtmlHelp. But they didn't get recognized. Started the whole project all over and somehow the error's gone.

Credits go to both for your efforts. Thanks
0
 

Author Closing Comment

by:MercuryKT
ID: 35044821
other alternate solution.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi,      I've been learning Spring and Jersey for the past few months and to say in simple, i am pretty much impressed with these frameworks. Many developers feel it awkward to implement a RESTful Web Services with such a popular Web Application Fr…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question