1.ActionLink
<%=Html.ActionLink("这是一个连接", "Index", "Home")%>
带有QueryString的写法
<%=Html.ActionLink("这是一个连接", "Index", "Home", new { page=1 },null)%>
<%=Html.ActionLink("这是一个连接", "Index", new { page=1 })%>
有其它Html属性的写法
<%=Html.ActionLink("这是一个连接", "Index", "Home", new { })%>
<%=Html.ActionLink("这是一个连接", "Index",null, new { })%>
QueryString与Html属性同时存在
<%=Html.ActionLink("这是一个连接", "Index", "Home", new { page = 1 }, new { id = "link1" })%>
<%=Html.ActionLink("这是一个连接", "Index" , new { page = 1 }, new { id = "link1" })%>
生成结果为:
<a href="/">这是一个连接</a>
带有QueryString的写法
<a href="/?page=1">这是一个连接</a>
<a href="/?page=1">这是一个连接</a>
有其它Html属性的写法
<a href="/?Length=4" >这是一个连接</a>
<a href="/" >这是一个连接</a>
QueryString与Html属性同时存在
<a href="/?page=1" >这是一个连接</a>
<a href="/?page=1" >这是一个连接</a>
2.RouteLink
跟ActionLink在功能上一样。
<%=Html.RouteLink("关于", "about", new { })%>
带QueryString
<%=Html.RouteLink("关于", "about", new { page = 1 })%>
<%=Html.RouteLink("关于", "about", new { page = 1 }, new { id = "link1" })%>
生成结果:
<a href="/about">关于</a>
<a href="/about?page=1">关于</a>
<a href="/about?page=1" >关于</a>
3.Form 2种方法
<%using(Html.BeginForm("index","home",FormMethod.Post)){%>
<%} %>
<%Html.BeginForm("index", "home", FormMethod.Post);//注意这里没有=输出%>
<%Html.EndForm(); %>
生成结果:
<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;" })%>
生成结果:
<input />
<input />
<input />
<input />
5.TextArea
<%=Html.TextArea("input5", Model.CategoryName, 3, 9,null)%>
<%=Html.TextAreaFor(a => a.CategoryName, 3, 3, null)%>
生成结果:
<textarea cols="9" >Beverages</textarea>
<textarea cols="3" >Beverages</textarea>
6.CheckBox
<%=Html.CheckBox("chk1",true) %>
<%=Html.CheckBox("chk1", new { @class="checkBox"}) %>
<%=Html.CheckBoxFor(a =>a.IsVaild, new { @class = "checkBox" })%>
生成结果:
<input checked="checked" />
<input class="checkBox" />
<input checked="checked" class="checkBox" />
7.ListBox
<%=Html.ListBox("lstBox1",(SelectList)ViewData["Categories"])%>
<%=Html.ListBoxFor(a => a.CategoryName, (SelectList)ViewData["Categories"])%>
生成结果:
<select >
<option value="1">Beverages</option>
<option value="2">Condiments</option>
<option selected="selected" value="3">Confections</option>
</select>
<select >
<option value="1">Beverages</option>
<option value="2">Condiments</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" })%>
生成结果:
<select >
<option value="">--Select One--</option>
<option value="1">Beverages</option>
<option value="2">Condiments</option>
<option selected="selected" value="3">Confections</option>
</select>
<select class="dropdownlist" >
<option value="">--Select One--</option>
<option value="1">Beverages</option>
<option value="2">Condiments</option>
</select>
本文转自:http://www.cnblogs.com/yuanhuaming/archive/2010/02/18/1669184.html
1.ActionLink
<%=Html.ActionLink("这是一个连接", "Index", "Home")%>
带有QueryString的写法
<%=Html.ActionLink("这是一个连接", "Index", "Home", new { page=1 },null)%>
<%=Html.ActionLink("这是一个连接", "Index", new { page=1 })%>
有其它Html属性的写法
<%=Html.ActionLink("这是一个连接", "Index", "Home", new { })%>
<%=Html.ActionLink("这是一个连接", "Index",null, new { })%>
QueryString与Html属性同时存在
<%=Html.ActionLink("这是一个连接", "Index", "Home", new { page = 1 }, new { id = "link1" })%>
<%=Html.ActionLink("这是一个连接", "Index" , new { page = 1 }, new { id = "link1" })%>
生成结果为:
<a href="/">这是一个连接</a>
带有QueryString的写法
<a href="/?page=1">这是一个连接</a>
<a href="/?page=1">这是一个连接</a>
有其它Html属性的写法
<a href="/?Length=4" >这是一个连接</a>
<a href="/" >这是一个连接</a>
QueryString与Html属性同时存在
<a href="/?page=1" >这是一个连接</a>
<a href="/?page=1" >这是一个连接</a>
2.RouteLink
跟ActionLink在功能上一样。
<%=Html.RouteLink("关于", "about", new { })%>
带QueryString
<%=Html.RouteLink("关于", "about", new { page = 1 })%>
<%=Html.RouteLink("关于", "about", new { page = 1 }, new { id = "link1" })%>
生成结果:
<a href="/about">关于</a>
<a href="/about?page=1">关于</a>
<a href="/about?page=1" >关于</a>
3.Form 2种方法
<%using(Html.BeginForm("index","home",FormMethod.Post)){%>
<%} %>
<%Html.BeginForm("index", "home", FormMethod.Post);//注意这里没有=输出%>
<%Html.EndForm(); %>
生成结果:
<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;" })%>
生成结果:
<input />
<input />
<input />
<input />
5.TextArea
<%=Html.TextArea("input5", Model.CategoryName, 3, 9,null)%>
<%=Html.TextAreaFor(a => a.CategoryName, 3, 3, null)%>
生成结果:
<textarea cols="9" >Beverages</textarea>
<textarea cols="3" >Beverages</textarea>
6.CheckBox
<%=Html.CheckBox("chk1",true) %>
<%=Html.CheckBox("chk1", new { @class="checkBox"}) %>
<%=Html.CheckBoxFor(a =>a.IsVaild, new { @class = "checkBox" })%>
生成结果:
<input checked="checked" />
<input class="checkBox" />
<input checked="checked" class="checkBox" />
7.ListBox
<%=Html.ListBox("lstBox1",(SelectList)ViewData["Categories"])%>
<%=Html.ListBoxFor(a => a.CategoryName, (SelectList)ViewData["Categories"])%>
生成结果:
<select >
<option value="1">Beverages</option>
<option value="2">Condiments</option>
<option selected="selected" value="3">Confections</option>
</select>
<select >
<option value="1">Beverages</option>
<option value="2">Condiments</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" })%>
生成结果:
<select >
<option value="">--Select One--</option>
<option value="1">Beverages</option>
<option value="2">Condiments</option>
<option selected="selected" value="3">Confections</option>
</select>
<select class="dropdownlist" >
<option value="">--Select One--</option>
<option value="1">Beverages</option>
<option value="2">Condiments</option>
</select>
本文转自:http://www.cnblogs.com/yuanhuaming/archive/2010/02/18/1669184.html