Go to home page mail me! RSS Feed

November 2009 Entries

Adding “class” attribute to htmlAttributes of the HtmlHelper in MVC

I’ve seen lots of questions on how you can add a “class” attribute to any html tag such as the “a” tag while using the HtmlHelper class in ASP.NET MVC. The problem here is “class” is a reserved keyword in .NET so you just can’t use “class” in the htmlAttributes object of the HtmlHelper class. i.e. this will work perfectly. <%=Html.ActionLink("Log in","Login", null, new { id = "idforthislink" } %> but this won’t <%=Html.ActionLink("Log in","Login", null, new { id = "idforthislink", class ="red" } %> It will error out on class. Here is the proper way of doing it. <%=Html.ActionLink("Log in","Login", null, new...

posted @ Friday, November 27, 2009 1:22 PM | Feedback (0)

Next entries »