It was a strange phenomenon. I was able to reproduce your error. I also managed to find out why this is happening and how to get around it.
Why is this happening
There is a collision between the System.Web.Mvc.Html and System.Web.WebPages.Html
As a result of a collision
System.Web.Mvc.Html
This namespace contains a method definition
LabelExtensions.Label (HtmlHelper, String, String)
As you noticed, this is a namespace that has a use case and causes a problem. It has only two overloads. (String) or (String, String) . During testing, this was the only option that appeared.
How to get around it
What you really wanted is a namespace
System.Web.WebPages.Html
This namespace contains a method definition
HtmlHelper.Label (String, String, IDictionary<String, Object>)
Now you can see that it is possible to add new { @class = "myClass" } .
Create your own instance
Get your own HtmlHelper and LabelExtension as follows:
Razor
@{ var h = new System.Web.WebPages.Html.HtmlHelper(); }
asp
<% var h = new System.Web.WebPages.Html.HtmlHelper(); %>
Make sure that it is not nested inside the razor block or <%= , because this will prevent its availability. It must be at the global page level.
Use correct label
Now you can use this:
Razor
@h.Label("firstName", "First Name", new { @class = "control-label" })
asp
<%= h.Label("firstName", "First Name", new { @class = "control-label" }) %>