HTML helpers are methods of the view's Html object (IHtmlHelper) and exist to aid in generating HTML. We may not know the exact syntax and URLs to routes can be tricky to generate, but there are two more important reasons why we use them. HTML helpers generate the appropriate code for display and editing purposes based on the model metadata, and they also include error and description placeholders. It is important to keep in mind that they are always based on the model.
In general, the built-in HTML helpers have two overloads:
- One that takes a strongly typed model (for example, EditorFor(x => x.FirstName))
- Another that takes dynamic parameters in the form of strings (for example,EditorFor("FirstName"))
Also, they all take an optional parameter, htmlAttributes, that can be used to add any attribute to the rendered HTML element (for example,TextBoxFor(x => x.FirstName, htmlAttributes: new...