HTML Helper Methods MVC
HTML Helper Methods MVC
NET MVC
5
In ASP.NET MVC Framework, helper methods:
Are extension methods to the Html Helper class, can be called only from
views.
An HTML helper is a method that is used to render html content in a view.
Simplifies the process of creating a view.
Allows generating HTML markup that you can reuse across the Web
application.
Html.ActionLink()
Html.BeginForm() and Html.EndForm()
Html.Label()
Html.TextBox()
Html.TextArea()
Html.Password()
Html.CheckBox()
Html.ActionLink()
Html.ActionLink() helper method allows you to generate a hyperlink that points to
an action method of a controller class.
@Html.ActionLink(<link_text>,<action_method>,<optional_controller>)
HTML HELPER METHODS IN ASP.NET MVC
5
An HTML helper is a method that is used to render html content in a view
Html.ActionLink()
Html.BeginForm() and Html.EndForm()
Html.Label()
Html.TextBox()
Html.TextArea()
Html.Password()
Html.CheckBox()
OR
We can use the “TextBox” Html helper class method.
o @Html.TextBox(“fullName”)
There are several overloaded versions. To set a value, along with name of a
textbox
o @Html.TextBox(“fullName”,”Adil”)
To set HTML attributes, use the following overloaded version. Note that: We are
passing HTML attributes (style and title) as an anonymous type.
We can use external style sheet to give the style to the textbox.
Applying bootstrap class to textbox.
If you want to use attributes that are reserved in Csharp programming
language like class, readonly etc. Then you have to use @ symbol before
the name of attribute.
Html.ActionLink()
Html.BeginForm() and Html.EndForm()
Html.Label()
Html.TextBox()
Html.Password()
Html.RadioButton()
Html.DropDownList()
Html.TextArea()
Html.CheckBox()
Html.hidden()