Standard Html Helpers

These helpers are used to render the most common types of HTML elements like as HTML text boxes, checkboxes etc. A list of most common standard html helpers is given below:

HTML Element Example
TextBox @Html.TextBox(“Textbox1”, “val”)
Output: <input id=”Textbox1″ name=”Textbox1″ type=”text” value=”val” />
TextArea @Html.TextArea(“Textarea1”, “val”, 5, 15, null)
Output: <textarea cols=”15″ id=”Textarea1″ name=”Textarea1″ rows=”5″>val</textarea>
Password @Html.Password(“Password1”, “val”)
Output: <input id=”Password1″ name=”Password1″ type=”password” value=”val” />
Hidden Field @Html.Hidden(“Hidden1”, “val”)
Output: <input id=”Hidden1″ name=”Hidden1″ type=”hidden” value=”val” />
CheckBox @Html.CheckBox(“Checkbox1″, false)
Output: <input id=”Checkbox1″ name=”Checkbox1″ type=”checkbox” value=”true” /> <input name=”myCheckbox” type=”hidden” value=”false” />
RadioButton @Html.RadioButton(“Radiobutton1”, “val”, true)
Output: <input checked=”checked” id=”Radiobutton1″ name=”Radiobutton1″ type=”radio” value=”val” />
Drop-down list @Html.DropDownList (“DropDownList1”, new SelectList(new [] {“Male”, “Female”}))
Output: <select id=”DropDownList1″ name=”DropDownList1″> <option>M</option> <option>F</option> </select>
Multiple-select Html.ListBox(“ListBox1”, new MultiSelectList(new [] {“Cricket”, “Chess”}))
Output: <select id=”ListBox1″ multiple=”multiple” name=”ListBox1″> <option>Cricket</option> <option>Chess</option> </select>

Tagged , . Bookmark the permalink.

Leave a Reply