Q: 如何为Html.TextBoxFor控件添加多个属性?
A: @Html.TextBoxFor(m => m.Email, new Dictionary<string, object>() { {"class", "input-material" }, {"data-msg", "Please enter your username" },{ "required", "true"} })
Q: 如何为输出HTML格式的字符串?
A: @Html.Raw(ViewBag.Content)
Q: 如何在视图中添加下拉框?
A: @Html.DropDownListFor(m => m.PropertyName, ViewBag.PropertyList as List<SelectListItem>, "-请选择-"),第三个参数用于在下拉框中添加一个默认值。
var propertyList = new List<SelectListItem>(); propertyList.Add(new SelectListItem() { Text = "", Value = "" }); ViewBag.PropertyList=propertyList;