HtmlHelper class  create the output html elements using the model properties in razor view. The property to be used to create the HTML is passed to the method as a lambda expression. It binds the model property to html elements to display value of model properties into html elements and also assigns the value of the html elements to the model properties while submitting web form. So always use HtmlHelper class in razor view instead of writing html tags directly.

The following figure shows the use of HtmlHelper class in the razor view

what is HtmlHelper  in mvc

As you can see in the above figure, @Html is an object of HtmlHelper class . (@ symbol is used to access server side object in razor syntax). Html is a property of type HtmlHelper included in base class of razor view WebViewPage. TextAreaFor () and DropDownListFor () is extension methods included in HtmlHelper class.

There are many extension methods for HtmlHelper class, which creates different html controls.

The following table lists HtmlHelper methods and html control each method generates.

HtmlHelper

Strogly Typed HtmlHelpers

Html Control

Html.ActionLink

Html.ActionLink

Anchor link

Html.TextBox

Html.TextBoxFor

Textbox

Html.TextArea

Html.TextAreaFor

TextArea

Html.CheckBox

Html.CheckBoxFor

Checkbox

Html.RadioButton

Html.RadioButtonFor

Radio button

Html.DropDownList

Html.DropDownListFor

Dropdown, combobox

Html.ListBox

Html.ListBoxFor

multi-select list box

Html.Hidden

Html.HiddenFor

Hidden field

Password

Html.PasswordFor

Password textbox

Html.Display

Html.DisplayFor

Html text

Html.Label

Html.LabelFor

Label

Html.Editor

Html.EditorFor

Generates Html controls based on data type of specified model property e.g. textbox for string property, numeric field for int, double or other numeric type.


Thanks.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like