ASP.NET MVC LabelFor Helper With HtmlAttributes
In ASP.NET MVC you have low-level control over your HTML. This simply means that you can write any html elements in your view as you wish. However for getting the advantage of Model Binding and Visual Studio Intellisense, ASP.NET MVC provides a shorter and tidier way to write html elements with the help of html helpers method.
LabelFor helper is one of the html helper method used to render html label element. ASP.NET MVC 2 ships with just a single overload for LabelFor helper method. There is no such overload of LabelFor helper which accepts htmlAttributes parameter like other html helpers accept.
This parameter is very important when you need to style html label with CSS class or when you need to add a tooltip message. Therefore in this article I will show you how easily you can creates your own LabelFor helper extension method which also accept htmlAttributes parameter.
Before I started to write some simple helper extension methods for LabelFor, it is worth to see the current helper method’s signature for LabelFor helper method. It only accept a single parameter expression.
View the Original article