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 { })
生成结果:
<input
checked="checked"
/><input name="chk1" type="hidden" value="false" />
<input
class="checkBox"
/><input name="chk1" type="hidden" value="false" />
<input
checked="checked" class="checkBox"
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"])
生成结果:
<select )
@Html.DropDownListFor(a
=> a.CategoryName, (SelectList)ViewData["Categories"], "--Select
One--", new { @class = "dropdownlist" })
生成结果:
<select ); 看清楚了没有等号的。
相关文章: