* * *
HTML helpers are used to modify HTML output.
* * *
## HTML Helpers
In MVC, HTML helpers are similar to traditional ASP.NET Web Form controls.
Like Web Form controls in ASP.NET, HTML helpers are used to modify HTML. However, HTML helpers are more lightweight. Unlike Web Form controls, HTML helpers do not have an event model or view state.
In most cases, an HTML helper is simply a method that returns a string.
In MVC, you can create your own helpers or use the built-in HTML helpers directly.
* * *
## Standard HTML Helpers
MVC includes standard helpers for most common HTML element types, such as HTML links and HTML form elements.
* * *
## HTML Links
The simplest way to render an HTML link is to use the HTML.ActionLink() helper.
In MVC, Html.ActionLink() does not link to a view. Instead, it creates a link to a controller action.
Razor syntax:
@Html.ActionLink("About this Website", "About")
ASP syntax:
The first parameter is the link text; the second parameter is the name of the controller action.
The above Html.ActionLink() helper outputs the following HTML:
About this Website
Some properties of the Html.ActionLink() helper:
| Property | Description |
| --- | --- |
| .linkText | The URL text (label), i.e., the inner text of the anchor element. |
| .actionName | The name of the action. |
| .routeValues | Values passed to the actionβa route-parameter object. |
| .controllerName | The name of the controller. |
| .htmlAttributes | Attributes for the URLβan object containing the HTML attributes to set on the element. |
| .protocol | The URL protocol, e.g., "http" or "https". |
| .hostname | The hostname of the URL. |
| .fragment | The URL fragment name (anchor name). |
**Note:** You can pass values to controller actions. For example, you can pass the ID of a database record to a database Edit action:
Razor syntax C#:
@Html.ActionLink("Edit Record", "Edit", new {Id=3})
Razor syntax VB:
@Html.ActionLink("Edit Record", "Edit", New With{.Id=3})
The above Html.ActionLink() helper outputs the following HTML:
Edit Record
* * *
## HTML Form Elements
The following HTML helpers can be used to render (modify and output) HTML form elements:
* BeginForm()
* EndForm()
* TextArea()
* TextBox()
* CheckBox()
* RadioButton()
* ListBox()
* DropDownList()
* Hidden()
* Password()
ASP.NET syntax C#: