ASP.NET MVC HtmlHelper用法大全
HTML扩展类的所有方法都有2个参数:
以textbox为例子
public static string TextBox( this HtmlHelper htmlHelper, string name, Object value, IDictionary<string, Object> htmlAttributes )
public static string TextBox( this HtmlHelper htmlHelper, string name, Object value, Object htmlAttributes )
这2个参数代表这个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 { >关于</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 ); %> 看清楚了没有等号的。
原文地址:http://www.cnblogs.com/cherry1990/archive/2011/05/18/MVC.html