HTML Helper
HTML Helper is just a method that returns a HTML string.
The string can represent any type of content that you want.
For
example, you can use HTML Helpers to render standard HTML tags like
HTML <input>, <button> and <img> tags
etc.
You can also create your own HTML Helpers to render more complex
content such as a menu strip or an HTML table for displaying database data.
Example:
HtmlHelper.ActionLink @Html.ActionLink(“Create New”, ”Create”, ”Home”)
In the above example, @Html is an object of HtmlHelper class &
ActionLink() is the extension method
Html is a property of
type HtmlHelper included in base class of razor view WebViewPage
HtmlHelper class generates html elements For example,
@Html.ActionList("Create New", "Create“, “Home”) would generate anchor tag
<a href="/Home/Create">Create New</a>
HTML Element
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>
@Html.ActionLink("HomePage", Index.new{style='color:red');
Output: <a href="Index" style="color:red">HomePage</a>
@Html.DisplayName("Enter your username");
@HTMLDisplayNameFor(model => model.studentName);
The following table lists HtmlHelper methods and html control:
HtmlHelper - Html.ActionLink
Html Control
- Anchor link
HtmlHelper - Html.ActionLinkFor
Html Control - Anchor
link
HtmlHelper - Html.TextBox
Strogly Typed HtmlHelpers
- Html.TextBoxFor
Html Control - Textbox
HtmlHelper - Html.TextArea
Strogly Typed HtmlHelpers - Html.TextAreaFor
Html Control - TextArea
HtmlHelper
- Html.CheckBox
Strogly Typed HtmlHelpers - Html.CheckBoxFor
Html Control - Checkbox
HtmlHelper - Html.RadioButton
Strogly Typed HtmlHelpers -
Html.RadioButtonFor
Html Control - Radio button
HtmlHelper - Html.DropDownList
Strogly Typed HtmlHelpers
- Html.DropDownListFor
Html Control - Dropdown, combobox
HtmlHelper - Html.ListBox
Strogly Typed HtmlHelpers
- Html.ListBoxFor
Html Control - Multi-select list box
HtmlHelper
- Html.Hidden
Strogly Typed HtmlHelpers - Html.HiddenFor
Html Control - Hidden Field
HtmlHelper - Password
Strogly Typed HtmlHelpers - Html.PasswordFor
Html Control - Password textbox
HtmlHelper
- Html.Display
Strogly Typed HtmlHelpers - Hmlt.DisplayFor
Html Control - Html text
HtmlHelper - Html.Label
Strogly Typed HtmlHelpers - Html.LabelFor
Html Control - Label
HtmlHelper - Html.DisplayName
Strogly Typed HtmlHelpers
- Html.DisplayNameFor
Html Control - Display
HtmlHelper
- Html.editory
Strogly Typed HtmlHelpers - Html.EditorFor
Html Control -
Generates html controls based on data type of specified model property eg.
textbox for string property numeric field for int, double or other numeric
type.
Disclaimer
All tutorials are for informational and educational
purposes only and have been made using our own routers, servers, websites and
other vulnerable free resources. we do not contain any illegal activity. We
believe that ethical hacking, information security and cyber security should be
familiar subjects to anyone using digital information and computers. Hacking
Truth is against misuse of the information and we strongly suggest against it.
Please regard the word hacking as ethical hacking or penetration testing every
time this word is used. We do not promote, encourage, support or excite any
illegal activity or hacking.