All methods of the HTML extension class have 2 parameters:

Source: Internet
Author: User
Tags actionlink

--Excerpt from Rocky Ren

All methods of the HTML extension class have 2 parameters:

Take a TextBox as an example

public static string TextBox (this htmlhelper htmlhelper, string name, Object value, idictionary<string, object> htm Lattributes)

public static string TextBox (this htmlhelper htmlhelper, string name, object value, Object htmlattributes)

These 2 parameters represent a collection of attributes for this HTML tag. Use the following method.

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= "/?=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>

<a href= "/about?page=1" id= "Link1" > About </a>

2 Methods of 3.Form

<%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,

<%=html.textbox ("input1")%>

<%=html.textbox ("Input2", model.categoryname,new{@style = "width:300px;"})%>

<%=html.textbox ("Input3", viewdata["Name"],new{@style = "width:300px;"})%>

<%=html.textboxfor (A = A.categoryname, new {@style = "width:300px;"}) %>

Build Result:

<input id= "input1" name= "input1" type= "text" value= ""/>

<input id= "Input2" name= "Input2" style= "width:300px;" type= "text" value= "Beverages"/>

<input id= "Input3" name= "Input3" style= "width:300px;" type= "text" value= ""/>

<input id= "CategoryName" name= "CategoryName" style= "width:300px;" type= "text" value= "Beverages"/>

5.TextArea

<%=html.textarea ("Input5", Model.categoryname, 3, 9,null)%>

<%=html.textareafor (A = A.categoryname, 3, 3, NULL)%>

Build Result:

<textarea cols= "9" id= "Input5" name= "Input5" rows= "3" >Beverages</textarea>

<textarea cols= "3" id= "CategoryName" name= "CategoryName" rows= "3" >Beverages</textarea>

6.CheckBox

<%=html.checkbox ("Chk1", True)%>

<%=html.checkbox ("Chk1", new {@class = "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.listbox ("LstBox1", (selectlist) viewdata["Categories"])%>

<%=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>

<option value= "4" >dairy products</option>

<option value= "5" >Grains/Cereals</option>

<option value= "6" >Meat/Poultry</option>

<option value= "7" >Produce</option>

<option value= "8" >Seafood</option>

</select>

<select id= "CategoryName" multiple= "multiple" name= "CategoryName" >

<option value= "1" >Beverages</option>

<option value= "2" >Condiments</option>

<option value= "3" >Confections</option>

<option value= "4" >dairy products</option>

<option value= "5" >Grains/Cereals</option>

<option value= "6" >Meat/Poultry</option>

<option value= "7" >Produce</option>

<option value= "8" >Seafood</option>

</select>

8.DropDownList

<%= html.dropdownlist ("Ddl1", (selectlist) viewdata["Categories"], "--select one--")%>

<%=html.dropdownlistfor (A = A.categoryname, (selectlist) viewdata["Categories"], "--select one--", new {@class = "DropDownList"})%>

Build Result:

<select id= "DDL1" name= "DDL1" >

<option value= "" >--select one--</option>

<option value= "1" >Beverages</option>

<option value= "2" >Condiments</option>

<option selected= "Selected" value= "3" >Confections</option>

<option value= "4" >dairy products</option>

<option value= "5" >Grains/Cereals</option>

<option value= "6" >Meat/Poultry</option>

<option value= "7" >Produce</option>

<option value= "8" >Seafood</option>

</select>

<select class= "DropDownList" id= "CategoryName" name= "CategoryName" >

<option value= "" >--select one--</option>

<option value= "1" >Beverages</option>

<option value= "2" >Condiments</option>

<option value= "3" >Confections</option>

<option value= "4" >dairy products</option>

<option value= "5" >Grains/Cereals</option>

<option value= "6" >Meat/Poultry</option>

<option value= "7" >Produce</option>

<option value= "8" >Seafood</option>

</select>

9.Partial View Templates

WebForm is called a custom control. functions are for reuse. But it's really hard to use a custom control on it.

<% html.renderpartial ("Dinnerform"); %> See clearly that there is no equal sign.

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.