May 12, 2021 ASP.NET
The HTML helper is used to modify the HTML output.
With MVC, html helpers are similar to traditional ASP.NET web Form controls.
Like ASP.NET form controls in the web, HTML helpers are used to modify HTML. B ut HTML helpers are lightweight. Unlike Web Form controls, HTML Helper does not have event models and view states.
In most cases, the HTML helper is simply a way to return a string.
With MVC, you can create your own helper or use the built-in HTML helper directly.
MVC contains standard helpers for most commonly used HTML element types, such as HTML links and HTML form elements.
The easiest way to render HTML links is to use HTML. ActionLink() helper.
With MVC, Html.ActionLink() is not connected to the view. It creates a connection to the controller operation.
Razor syntax:
ASP syntax:
The first argument is the linked text, and the second argument is the name of the controller operation.
The Html.ActionLink() helper above outputs the following HTML:
Some properties of the Html.ActionLink() helper:
Attributes | describe |
---|---|
.linkText | URL text (label), internal text of the positioning point element. |
.actionName | The name of the operation (Action). |
.routeValues | The value transmitted to the action is an object that contains routing parameters. |
.controllerName | The name of the controller. |
.htmlAttributes | The properties of the URL are an object that contains the HTML feature set for this element. |
.protocol | URL protocol, such as "http" or "https". |
.hostname | The host name of the URL. |
.fragment | URL fragment name (positioning point name). |
Note: You can pass values to controller actions. For example, you can pass the id of a database record to a database Edit operation:
Razor Syntax C#:
Razor syntax VB:
The Html.ActionLink() helper above outputs the following HTML:
The following HTML helpers can be used to render (modify and output) HTML form elements:
ASP.NET Syntax C#:
That's ASP.NET MVC HTML helper for the 1000s.