ASP.NET MVC HTML and URL Helpers.
Hello, friends in this article we will learn about HTML and URL Helpers. Consider a situation where the development team working on the e-commerce shopping website application needs to give an option to a user should be able to navigate the different web pages. ASP.NET MVC offers a standard set of helper method. These helpers help you work with HTML and URLs.
The benefits of using these helpers are that they help you generate links and URLs form the routing configuration.
The benefits of using these helpers are that they help you generate links and URLs form the routing configuration.
Some HTML Helpers Methods are :
- Html.ActionLink()
- Html.BeginForm() and Html.EndForm()
- Html.Label() and Html.LabelFor()
- Html.DisplayName() and Html.DisplayNameFor()
- Html.TextBox() and Html.TextBoxFor()
- Html.TextArea() and Html.TextAreaFor()
- Html.EditorFor()
- Html.Ediotr()
- Html.Password() and Html.PasswordFor()
- Html.HiddenFor()
- Html.CheckBox() and Html.CheckBoxFor()
- Html.DropDownList() and Html.DropDownList()
- Html.RedioButton() and Html.RedioButtonFor()
- Url.Action()
1. Html.ActionLink()
The Html.ActionLink() Method generates a hyperlink (ancor tag) that points to a controller's action metho.The Html.ActionLink() helper uses the internal rougting process to generate the target URL for the hyperlink.
The syntax of Html.ActionLink()
@Html.ActionLink("Link Text", "ActionName","Controller Name",HtmlAttributes )
This Html.ActionLink() generate following HTML markup:
<a href="Controller/ActionName">Link Text</a>
2.Html.BeginForm() and Html.EndForm()
The Html.BeginForm() Method indicate the start of a form. This helper method coordinates with the routing engine to generate a proper URL.
The syntax of Html.BeginForm()
@{Html.BeginForm("ActionName","Controller Name");}
The preceding syntax will generate the following markup:
<form action="ControllerName/ActionName" method="post">
Once you created successfully form you need to close the <form> tag by rendering a closing </form> tag. Html.EndForm() Helper method render the form end tag </form>
In order to avoid to use Html.EndForm() you can use the following syntax:
@using(Html.BeginForm("ActionName","ControllerName"){
//Write your code here
}
The preceding syntax will generate the following markup:
<form action="ControllerName/ActionName" >
<!--Write your code here-->
</form>
<!--Write your code here-->
</form>







Good article
ReplyDeleteNice
ReplyDelete