ASP.NET provides a wide range of built-in HTML helpers that can be used as per the user’s choice as there are multiple overrides available for them. There are three types of built-in HTML helpers offered by ASP.NET.
1. Standard HTML Helper
The HTML helpers that are mainly used to render HTML elements like text boxes, checkboxes, Radio Buttons, and Dropdown lists, etc. are called Standard HTML helpers.
List of Standard HTML Helpers
@Html.ActionLink() - Used to create link on html page @Html.TextBox() - Used to create text box @Html.CheckBox() - Used to create check box @Html.RadioButton() - Used to create Radio Button @Html.BeginFrom() - Used to start a form @Html.EndFrom() - Used to end a form @Html.DropDownList() - Used to create drop down list @Html.Hidden() - Used to create hidden fields @Html.label() - Used for creating HTML label is on the browser @Html.TextArea() - The TextArea Method renders textarea element on browser @Html.Password() - This method is responsible for creating password input field on browser @Html.ListBox() - The ListBox helper method creates html ListBox with scrollbar on browser
2. Strongly-Typed HTML Helper
The Strongly-Typed HTML helper takes a lambda as a parameter that tells the helper, which element of the model to be utilized in the typed view. The Strongly typed views are used for rendering specific sorts of model objects, rather than using the overall View-Data structure.
List of strongly-Typed HTML Helper
@Html.HiddenFor() @Html.LabelFor() @Html.TextBoxFor() @Html.RadioButtonFor() @Html.DropDownListFor() @Html.CheckBoxFor() @Html.TextAreaFor() @Html.PasswordFor() @Html.ListBoxFor()
The functionality of all of these are the same as above but they are used with modal classes. Now, as we know we need a model class to use strongly typed HTML. So firstly we will add a model class as follows
Now write the following code in the controller. And then add a view with the default properties.
Now write the HTML as follows:
The output will be as follows:
3. Templated HTML Helper
The templated HTML Helper is used for data display and input. It generates HTML automatically as per model property and it can generate HTML for a complete model with a single tag. These are divided into two categories
- Display Template
- Editor Template
List of Templated HTML Helpers
Display @Html.Display() @Html.DisplayFor() @Html.DisplayName() @Html.DisplayNameFor() @Html.DisplayText() @Html.DisplayTextFor() @Html.DisplayModelFor() Edit / Input @Html.Editor() @Html.EditorFor() @Html.EditorForModel()
Now, here we can use the previously created model class and then we should write this code in the controller
Now add the view with all the default properties and write the following code
The output will be as follows
- Inline HTML Helper - HTML Helpers in ASP.NET MVC
- Basic CRUD (Create, Read, Update, Delete) in ASP.NET MVC Using C# and Entity Framework
- Types of CSS (Cascading Style Sheet)
- MIME Media Types
- Google Maps | Types
- How to split a column of list in different rows using bootstrap?
- How to open a different modal that is inside of a list ?
- HTML | <html> Tag
- HTML Course | Structure of an HTML Document
- HTML Course | Basics of HTML
- HTML | DOM HTML Object
- HTML | <html> xmlns Attribute
- What is the difference between <html lang="en'> and <html lang="en-US'> ?
- HTML | scoped Attribute
- HTML | DOM lang Property
- HTML | <section> Tag
- HTML | DOM Style backgroundClip Property
- HTML | DOM Style borderTop Property
- HTML | <th> valign Attribute
- HTML | <col> align Attribute
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.