Monday, 24 December 2018

What are Html helpers in MVC

HTML helpers are extension methods used to render HTML content in a view

Below are the few HTML helpers:

TextBox HTML helper:
@Html.TextBox("firstname") 

Label HTML helper:
@Html.Label("fisrtname""First Name")

Password HTML helper:
@Html.Password("Password")

Multi-line textbox with 4 rows and 10 columns
@Html.TextArea("Comments""", 4, 10, null)

Hidden HTML helper:
@Html.Hidden("id")

Hyperlink HTML helper:
@Html.ActionLink("About""About""Home")

Dropdown HTML helper:
@Html.DropDownList("Departments"new List<SelectListItem>

    new SelectListItem { Text = "IT", Value = "1", Selected=true},
    new SelectListItem { Text = "HR", Value = "2"},
    new SelectListItem { Text = "Payroll", Value = "3"}
}, "Select Department") 

RadioButton HTML helper:
Male:   @Html.RadioButton("Gender","Male")  
Female: @Html.RadioButton("Gender","Female")  
ListBox HTML helper:
@Html.ListBoxFor(m => m.SelectedCities, Model.Cities, new { size = 4 })
You can also create your own HTML helpers.


No comments:

Post a Comment