- In Mvc html helpers are much like ASP.NET web form controls.
- Html helpers are used to modify HTML But these helpers are very light weight.
- Html helpers does not have a view state and a event modal but we have in web form controls.
- Html helper basically a method that returns a string.
- In MVC we can the inbuild html helpers or we can create our own helpers.
Standard HTML Helpers
- HTML Links
- The standard way to use the HTML link in MVC is by using the HTML.ActionLink() helper.
- With MVC Action Link create a link to the controller Action.
@Html.ActionLink("About this Project", "About")
HTML output
<a href="/Home/About">About this Project</a>
Also we can pass the parameter value to the action
@Html.ActionLink("Delete Record", "Delete", new {Id=2})
HTML Output
<a href="/Home/Delete/3">Delete Record</a>
HTML Form Elements
The following html heplers are used to render(modify and output) html form elements :
- BeginForm()
- EndForm()
- TextArea()
- TextBox()
- CheckBox()
- RadioButton()
- ListBox()
- DropDownList()
- Hidden()
- Password()
<%= Html.ValidationSummary("Create was unsuccessful. Please correct the
errors and try again.") %>
<% using (Html.BeginForm()){%>
<label for="FirstName">First Name:</label>
<%= Html.TextBox("FirstName") %>
<%= Html.ValidationMessage("FirstName", "*") %>
<label for="LastName">Last Name:</label>
<%= Html.TextBox("LastName") %>
<%= Html.ValidationMessage("LastName", "*") %>
<label for="Password">Password:</label>
<%= Html.Password("Password") %>
<%= Html.ValidationMessage("Password", "*") %>
<label for="Password">Confirm Password:</label>
<%= Html.Password("ConfirmPassword") %>
<%= Html.ValidationMessage("ConfirmPassword", "*") %>
<label for="Profile">Profile:</label>
<%= Html.TextArea("Profile", new {cols=60, rows=10})%>
<%= Html.CheckBox("Receiveletter") %>
<label for="Receiveletter" style="display:inline">Receive letter?</label>
<input type="submit" value="Register" />
<%}%>
<% using (Html.BeginForm()){%>
<label for="FirstName">First Name:</label>
<%= Html.TextBox("FirstName") %>
<%= Html.ValidationMessage("FirstName", "*") %>
<label for="LastName">Last Name:</label>
<%= Html.TextBox("LastName") %>
<%= Html.ValidationMessage("LastName", "*") %>
<label for="Password">Password:</label>
<%= Html.Password("Password") %>
<%= Html.ValidationMessage("Password", "*") %>
<label for="Password">Confirm Password:</label>
<%= Html.Password("ConfirmPassword") %>
<%= Html.ValidationMessage("ConfirmPassword", "*") %>
<label for="Profile">Profile:</label>
<%= Html.TextArea("Profile", new {cols=60, rows=10})%>
<%= Html.CheckBox("Receiveletter") %>
<label for="Receiveletter" style="display:inline">Receive letter?</label>
<input type="submit" value="Register" />
<%}%>
No comments:
Post a Comment