1.超链接
Html.ActionToLink("首页","Index","Home",new{name="lixiwei",pwd="213"},new{id="a1",@class="txt"});
优点:不用担心路由规则被更改。
2.防二次编码
MvcHtmlString.Create(ViewData["style"].ToString())
3.Html.DropDownList("city")
在控制器中写下拉选项:
List<SelectListItem> city = new List<SelectListItem>()
{
new SelectListItem(){Text="北京",Value="1"},
new SeleteListItem(){Text="济南",Value="2" Selected=true}
}
如果ViewData的key与DropDownList名称一致,自动填充。
4.单选按钮
男Html.RadioButton("gender","男"); 女Html.RadiotButton("gender","女');.
5.文本框
Html.TextBox()
补充:
Html.Label 和 Html.LaberFor 的区别 其他控件同理:
导入Model
Html.TextBoxFor(u=>u.UserName);