0% found this document useful (0 votes)
9 views4 pages

HTML Helper Methods MVC

Uploaded by

Madhuri Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

HTML Helper Methods MVC

Uploaded by

Madhuri Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

HTML HELPER METHODS IN ASP.

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.

Some of the commonly used helper methods while developing an MVC


application are as follows:

 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.

The general syntax of the Html.ActionLink() helper method is as follows:

@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

Some of the commonly used helper methods while developing an MVC


application are as follows:

 Html.ActionLink()
 Html.BeginForm() and Html.EndForm()
 Html.Label()
 Html.TextBox()
 Html.TextArea()
 Html.Password()
 Html.CheckBox()

 To create the html for a textbox with id = “fullName” and name =


“fullName”
o <input type=”text” name = “fullName” id = “fullName”>

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 HELPER METHODS IN ASP.NET MVC


5
Some of the commonly used helper methods while developing an MVC
application are as follows:

 Html.ActionLink()
 Html.BeginForm() and Html.EndForm()
 Html.Label()
 Html.TextBox()
 Html.Password()
 Html.RadioButton()
 Html.DropDownList()
 Html.TextArea()
 Html.CheckBox()
 Html.hidden()

 IS IT COMPULSORY TO USE HTML HELPERS?


o No, you can type the required html, but using html helpers will greatly
reduce the amount of HTML markup that we have to write in a view.
Views should be as simple as possible.

You might also like