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 { >这是一个连接</a>

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>

Form 2种方法

<%using(Html.BeginForm("index","home",FormMethod.Post)){%>
<%} %>
<%Html.BeginForm("index", "home", FormMethod.Post);//注意这里没有=输出%> 
<%Html.EndForm(); %>
生成结果:
<form action="/home/index" method="post"></form>

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 />

TextArea

<%=Html.TextArea("input5", Model.CategoryName, 3, 9,null)%>
<%=Html.TextAreaFor(a => a.CategoryName, 3, 3, null)%>
生成结果:
<textarea cols="9" >Beverages</textarea>

CheckBox

<%=Html.CheckBox("chk1",true) %>
<%=Html.CheckBox("chk1", new { @class="checkBox"}) %>
<%=Html.CheckBoxFor(a =>a.IsVaild, new { @class = "checkBox" })%>
生成结果:
<input checked="checked" />

ListBox

<%=Html.ListBox("lstBox1",(SelectList)ViewData["Categories"])%>
<%=Html.ListBoxFor(a => a.CategoryName, (SelectList)ViewData["Categories"])%>
生成结果:
<select >Dairy Products</option>

DropDownList

<%= Html.DropDownList("ddl1", (SelectList)ViewData["Categories"], "--Select One--")%>
<%=Html.DropDownListFor(a => a.CategoryName, (SelectList)ViewData["Categories"], "--Select One--", new { @class = "dropdownlist" })%>
生成结果:
<select >Seafood</option>
</select>

相关文章:

  • 2022-02-04
  • 2021-11-05
  • 2021-05-21
  • 2022-12-23
  • 2021-08-08
  • 2021-06-03
  • 2021-06-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案