"MVC" ASP. NET MVC HtmlHelper usage Daquan

Source: Internet
Author: User
Tags actionlink

1.ActionLink
<%=html.actionlink ("This is a connection", "Index", "Home")%>
The wording with QueryString
<%=html.actionlink ("This is a connection", "Index", "Home", new {page=1},null)%>
<%=html.actionlink ("This is a connection", "Index", new {page=1})%>
There are other HTML attributes to be written
<%=html.actionlink ("This is a connection", "Index", "Home", new {id= "Link1"})%>
<%=html.actionlink ("This is a connection", "Index", NULL, new {id= "Link1"})%>
QueryString and HTML attributes exist at the same time
<%=html.actionlink ("This is a connection", "Index", "Home", new {page = 1}, new {id = "Link1"})%>
<%=html.actionlink ("This is a connection", "Index", new {page = 1}, new {id = "Link1"})%>
The resulting result is:
<a href= "/" > This is a connection </a>
The wording with QueryString
<a href= "/?page=1" > This is a connection </a>
<a href= "/?page=1" > This is a connection </a>
There are other HTML attributes to be written
<a href= "/? Length=4 "id=" Link1 "> This is a connection </a>
<a href= "/" id= "Link1" > This is a connection </a>
QueryString and HTML attributes exist at the same time
<a href= "/?page=1" id= "Link1" > This is a connection </a>
<a href= "/?page=1" id= "Link1" > This is a connection </a>
2.RouteLink

Same as ActionLink in function.

<%=html.routelink ("About", "about", new {})%>
With QueryString
<%=html.routelink ("About", "about", new {page = 1})%>
<%=html.routelink ("About", "about", new {page = 1}, new {id = "Link1"})%>
Build Result:
<a href= "/about" > About </a>
<a href= "/about?page=1" > About </a>
3.Form2 different methods
<%using (Html.BeginForm ("index", "Home", FormMethod.Post)) {%>
<%}%>
<%html.beginform ("index", "Home", formmethod.post);//Note there is no = output%>
<%html.endform (); %>
Build Result:
<form action= "/home/index" method= "POST" ></form>

4.TextBox, Hidden
Build Result:
<input id= "CategoryName" name= "CategoryName" style= "width:300px;" type= "text" value= "Beverages"/>

5.TextArea
<%=html.textareafor (A = A.categoryname, 3, 3, NULL)%>
Build Result:
<textarea cols= "3" id= "CategoryName" name= "CategoryName" rows= "3" >Beverages</textarea>

6.CheckBox
<%=html.checkboxfor (a =>a.isvaild, new {@class = "checkbox"})%>
Build Result:
<input checked= "Checked" id= "Chk1" name= "Chk1" type= "checkbox" Value= "true"/><input name= "Chk1" type= "hidden "Value=" false "/>
<input class= "checkbox" id= "Chk1" name= "Chk1" type= "checkbox" Value= "true"/><input name= "Chk1" type= "hidden" Value= "false"/>
<input checked= "Checked" class= "checkbox" id= "Isvaild" name= "Isvaild" type= "checkbox" Value= "true"/><input Name= "Isvaild" type= "hidden" value= "false"/>
7.ListBox
<%=html.listboxfor (A = A.categoryname, (selectlist) viewdata["Categories"])%>
Build Result:
<select id= "LstBox1" multiple= "multiple" name= "LstBox1" >
<option value= "1" >Beverages</option>
<option value= "2" >Condiments</option>
<option selected= "Selected" value= "3" >Confections</option>
</select>
<select id= "CategoryName" multiple= "multiple" name= "CategoryName" >
<option value= "1" >Beverages</option>
<option value= "2" >Condiments</option>
</select>
8.DropDownList
<%= html.dropdownlist ("Ddl1", (selectlist) viewdata["Categories"],  
Build Result:
<select id= "DDL1" name= "DDL1" >
<select class= "DropDownList" id= "CategoryName" name= "CategoryName" >
</select>
This article transferred from: http://www.cnblogs.com/yuanhuaming/archive/2010/02/18/1669184.html

"MVC" ASP. NET MVC HtmlHelper usage Daquan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.