HTML Helpers are methods in ASP.NET MVC that help us generate HTML elements from Razor View.
They are used to create form elements like: Textbox, Label, Dropdown, Password, ActionLink, etc.
HTML Helpers generate HTML code inside Razor View.
These are built-in helper methods that generate basic HTML controls.
@Html.TextBox("name")
@Html.Password("password")
@Html.TextArea("message")
@Html.CheckBox("isActive")
@Html.RadioButton("gender", "Male")
@Html.DropDownList("countries",new SelectList(new[] { "USA", "India", "UK" }))
@Html.Hidden("userId", 101)
These helpers work with model properties.
@Html.TextBoxFor(m => m.Name)
@Html.TextAreaFor(m => m.Description)
@Html.CheckBoxFor(m => m.IsActive)
@Html.RadioButtonFor(m => m.Gender, "Male")
@Html.ActionLink("Home","Index","Home")
@using (Html.BeginForm()) { @Html.Label("Name") @Html.TextBox("Name") <input type = "submit" value="Save"/> }
Example:
✔ HTML Helpers generate HTML elements
✔ Used inside Razor View
✔ Support Model Binding
✔ Reduce manual HTML coding