I am using ASP.Net MVC 3, have referenced all the proper DLLs (see included screenshots), but for some reason I get a this compilation error.



Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This was an odd occurrence. I was able to reproduce your error. I was also able to figure out why it was happening and how to bypass it.
Why It Occurs
There is a namespace collision between
System.Web.Mvc.HtmlandSystem.Web.WebPages.HtmlWhat the result of the collision was
System.Web.Mvc.Html
This namespace holds a definition for the method
LabelExtensions.Label (HtmlHelper, String, String)As you will notice, this is the namespace which takes precedent and causes the problem. It has only two overloads.
(String)or(String, String). While testing, this was the only option which showed up.How to bypass it
What you really wanted was this namespace
System.Web.WebPages.Html
This namespace holds a definition for the method
HtmlHelper.Label (String, String, IDictionary<String, Object>)You can now see that the availability to add
new { @class = "myClass" }is present.Create your own instance
Get your own
HtmlHelperand bypass theLabelExtensionlike this:razor
asp
Make sure that this is not nested inside of a razor or
<%=block because it will prevent it from being available. It needs to be at the global level of the page.Use the correct label
Now you may use this:
razor
@h.Label("firstName", "First Name", new { @class = "control-label" })asp
<%= h.Label("firstName", "First Name", new { @class = "control-label" }) %>