Introduction
In this article, we will learn about Standard HTML helpers in MVC 5 and learn the advantages of using these helpers in ASP.NET MVC 5
We will also design a student registration page, shown below, using standard HTML helpers.

In this article, you will learn the following points about Standard HTML Helpers in MVC 5.
- What is a Standard HTML helper in Asp.NET MVC5?
- List of standard HTML helpers
- How to use Standard HTML helpers on View?.
- What are some examples of Standard HTML helpers?
- Advantages of using Standard HTML Helpers
- Interview Question & Home Work
The following are the previous top articles on ASP.NET MVC 5
- HTML Helpers with example In MVC 5
- Razor View Engine In ASP.NET MVC 5
- Model in ASP.NET MVC 5
- Action Method in MVC 5 with example
What is a Standard HTML helper in Asp.NET MVC5?
- Standard HTML helpers are used to render the most common type of HTML controls like Label,TextBox, Password, TextArea, CheckBox, RadioButtion, DropDownList, Listbox,Display,Editor and ActionLink etc.
- HTML helpers always start with @HTML. Ther are an object of Html helper class.@ symbol used to access the server-side code. The extension method of the HTML helper class has several overloaded methods. We can use it as per our requirement.
- HTML is a property of type HtmlHelper included in the base class of razor view WebViewPage. TextBox() or TextBoxFor()... are extension methods included in HtmlHelper class.
- The HtmlHelper class generates HTML elements. For example,@Html.ActionLink("Add Empoyee", "Create","Employee") would generate the anchor tag <a href="/Employee/Create">Add Empolyee</a>.
List of Standard HTML Helpers In ASP.NET MVC 5
- @Html.TextBox
- @Html.Password
- @Html.TextArea
- @Html.CheckBox
- @Html.RadioButton
- @Html.DropDownList
- @Html.ListBox
- @Html.Hidden
- @Html.Display
- @Html.Editor
- @Html.ActionLink
- @Html.BeginForm
- @Html.Label
@Html.TextBox()
TextBox() helper method is a loosely typed extension method that is used to create textbox(<input type=”text”>) element in razor view.
@Html.TextBox() method inside the “System.Web.Mvc.Html” namespace. The return type is “MvcHtmlString”.
TextBox() Method Signature
MvcHtmlString Html.TextBox(string name, string value, object htmlAttributes)
The TextBox() method is a loosely typed method because it has a name parameter that is a string. It automatically displays the value of the model property in a textbox and vice-versa. The name parameter can be a model class property. The value should be an object value of the property. The third parameter is that the HTML attribute can provide CSS or Id to the textbox. It has several overload methods we can use as per our requirement.
How to use TextBox() in Razor view
@Html.TextBox("txtUserName", "", new { @class = "form-control" })
Html Result
<input class="form-control" id="txtUserName" name="txtUserName" type="text" value="">
Output

How to set default value to TextBox() in Razor view
@Html.TextBox("txtUserName", "Test Value", new { @class = "form-control" })
@Html.Password()
The HTML helper class is used to generate HTML elements. The Password() helper method is a loosely typed extension method that is used to create textbox(<input type=”password”>) element in razor view.
@Html.Password() method inside the “System.Web.Mvc.Html” namespace. The return type is “MvcHtmlString”.
Password() Method Signature
MvcHtmlString Html.Password(string name, string value, object htmlAttributes)
The Password() method is a loosely typed method because its name parameter is a string. The name parameter can be a model class property. The value should be an object value of the property. So it automatically displays a value of the model property in a password and visa-versa. The third parameter is that the HTML attribute can provide CSS or Id to the Password. It has several overload methods we can use as per our requirement.
How to use Password() Helper in Razor view
@Html.Password("Password", "", new { @class = "form-control" }
Html Result
<input class="form-control" id="Password" name="Password" type="password" value="">
Output

@Html.TextArea()
TextArea() helper method is loosely typed extension method used to create a TextArea(<textarea cols="20" id="Address" name="Address" rows="2"> </textarea>) element in razor view.
@Html.TextArea() method inside the “System.Web.Mvc.Html” namespace. The return type is “MvcHtmlString”.
TextArea() Method Signature
MvcHtmlString Html.TextArea(string name, string value, object htmlAttributes)
The TextArea() method is a loosely typed method because its name parameter is a string. The name parameter can be model class property. The value should be an object value of the property. It automatically displays a value of the model property in a textarea and visa-versa. The third parameter is that an HTML attribute can provide CSS, Id to the TextArea. It has several overload methods we can use as per our requirement.
How to use TextArea() Helper in Razor view
@Html.TextArea("Address", " ", new { @class = "form-control",id="IdAddress" })
Html Result
<textarea class="form-control"
cols="20"
id="IdAddress"
name="Address"
rows="2">
</textarea>
Output

@Html.CheckBox():
This HTML helper class is used to generate HTML elements. The CheckBox() helper method is a loosely typed extension method which is used to create CheckBox(<input type="checkbox" >) element in razor view.
@Html.CheckBox() method inside the “System.Web.Mvc.Html” namespace. The return type is “MvcHtmlString”.
CheckBox() Method Signature
MvcHtmlString CheckBox(string name, bool isChecked, object htmlAttributes)
The CheckBox() method is a loosely typed method because its name parameter is a string. The name parameter can be model class property. The value should be an object value of the property, so it automatically displays a value of the model property in a CheckBox and visa-versa. The third parameter is an HTML attribute that can add CSS and the Id to the CheckBox. It has several overload methods we can use as per our requirement.
How to use CheckBox() Helper in Razor view
@Html.CheckBox("Dancing")
How to set CheckBox() default as checked
@Html.CheckBox("Cricket", true)
Html Result
<input checked="checked" id="Cricket" name="Cricket" type="checkbox" value="true">
<input id="Dancing" name="Dancing" type="checkbox" value="false">
Output

@Html.RadioButton()
This HTML helper class is used to generate HTML elements. The RadioButton() helper method is a loosely typed extension method which is used to create RadioButton(<input type="radio" >) element in razor view.
@Html.RadioButton() method inside the “System.Web.Mvc.Html” namespace. And return type is “MvcHtmlString”.
RadioButton() Method Signature
MvcHtmlString RadioButton(string name, object value, bool isChecked, object htmlAttributes)
The RadioButton() method is a loosely typed method because its name parameter is a string. The name parameter can be model class property. The value should be an object value of the property so that it automatically displays a value of the model property in a RadioButton and visa-versa. The third parameter is an HTML attribute that can add CSS and Id to the RadioButton. It has several overload methods we can use as per our requirement.
How to use RadioButton() Helper in Razor view
Example: Male and Female Gender
@Html.RadioButton("Gender", "Male", true, new { id = "male" }) Male
@Html.RadioButton("Gender", "Female", false, new { id = "female" }) Female
How to set RadioButton() default as checked
@Html.RadioButton("Gender", "Male", true, new { id = "male" }) Male
Html Result
<input checked="checked" id="male" name="Gender" type="radio" value="Male">
<input id="female" name="Gender" type="radio" value="Female">
Output





Sourav Kumar DasPosted Nov 13, 2019, 10:51 PM
Nice Useful article for basics of MVC Sir.