What is the use of HTML Helpers in ASP.NET MVC ?
If you are learning ASP.NET MVC, you will ask what is html.beginform or other such tags.
What is HTML Helper provide or what is the use of it ?
A HTML Helper is just a method that returns a HTML string. The string can represent any type of content that you want. For example, you can use HTML Helpers to render standard HTML tags like HTML <input>, <button> and <img> tags etc.
Just like web form controls in ASP.NET, HTML helpers are used to modify HTML.But HTML helpers are more lightweight. Unlike Web Form controls, an HTML helper does not have an event model and a view state.
Standard Helpers: MVC includes standard helpers for the most common types of HTML elements, like HTML links and HTML form elements.
HTML Links: The easiest way to render an HTML link in is to use the HTML.ActionLink() helper.
With MVC, the Html.ActionLink() does not link to a view. It creates a link to a controller action.
Razor Syntax: @Html.ActionLink("Be Master of One and Jack of All", "Info")
ASP Syntax: <%=Html.ActionLink("Be Master of One and Jack of All", "Info")%>
The first parameter is the link text, and the second parameter is the name of the controller action.
The Html.ActionLink() helper above, outputs the following HTML:
<a href="/Home/About">About this Website</a>
HTML Form Elements:
There following HTML helpers can be used to render (modify and output) HTML form elements:
- BeginForm()
- EndForm()
- TextArea()
- TextBox()
- CheckBox()
- RadioButton()
- ListBox()
- DropDownList()
- Hidden()
- Password()
What do you think ?
I hope you will enjoy the HTML Helpers while programming with ASP.NET MVC.
I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.