The HTML helper is used to modify the HTML output.
HTML Helper
The HTML helper is used to modify the html,html helper without the event model and view state. In most cases, the HTML helper is simply a way to return a string.
Standard HTML Helper
MVC contains standard helpers for most common types of HTML elements, such as HTML links and HTML form elements.
HTML Links
The simplest way to render an HTML link is to use HTML. ActionLink () helper.
Does not connect to the view through Mvc,html.actionlink (). It creates a connection to the Controller action (Director action).
Razor Syntax:
@Html. ActionLink ("About the Website", "about")
The first parameter is the link text, and the second parameter is the name of the controller action.
Above the Html.ActionLink () helper, output the following Html:
<href= "/home/about">about this Website</a >
Some parameters of the Html.ActionLink () helper:
Parameters |
Description |
LinkText |
The inner text of the anchor element. |
ActionName |
The name of the action. |
Controllername |
The name of the controller. |
Protocol |
URL protocol, such as "http" or "https". |
Hostname |
The host name of the URL. |
Fragment |
The URL fragment name (anchor name). |
Routevalues |
An object that contains the route parameters. |
Htmlattributes |
An object that contains the HTML attributes to set for the element. |
Note: You can pass a value to a controller action. For example, you can pass the ID of a database record like a database edit operation.
Razor Syntax C #:
@Html. ActionLink ("Edit Record", "edit", new {id=3})
Above the Html.ActionLink () helper, output the following Html:
<href= "/HOME/EDIT/3">Edit Record</a>
HTML form Elements
The following HTML helper can be used to render (modify and Output) HTML form elements:
- BeginForm ()
- EndForm ()
- TextArea ()
- TextBox ()
- CheckBox ()
- RadioButton ()
- ListBox ()
- DropDownList ()
- Hidden ()
- Password ()
Understanding the MVC programming model in ASP. 4th HTML Helper