Html Helpers



HtmlHelper Class:

 HtmlHelper Class  represents support for rendering HTML controls in a view.
    The ViewPage class has an HtmlHelper property named Html like follow













When you look at the methods of HtmlHelper, you’ll notice that it’s pretty sparse. This property is really an anchor point for attaching extension methods. When you import the System.Web.Mvc.Html namespace (imported by default in the default template), the Html property suddenly lights up with a bunch of helper methods.


In following screen shot u can observe it  





HtmlHelper Methods

ASP.NET MVC 2 includes support for strongly typed HTML helpers, which allow you to specify
Model properties using a Lambda expression rather than as strings.
For example, where you would have previously used <%: Html.TextBox(“PropertyName”) %> in ASP.NET MVC 1, you can now use <%: Html.TextBoxFor(m => m.PropertyName) %>.
Replacing strings with expressions provides a number of benefits, including type checking, IntelliSense, and simpler refactoring.
We have following important strongly typed Html Helper Methods :-
  • Html.Encode
  • Html.TextBox
  • Html.ActionLink and Html.RouteLink
  • Html.BeginForm
  • Html.Hidden
  • Html.DropDownList and Html.ListBox
  • Html.Password
  • Html.RadioButton
  • Html.Partial and Html.RenderPartial
  • Html.Action and Html.RenderAction
  • Html.TextArea
  • Html.ValidationMessage
  • Html.ValidationSummary