模型:
public class Product
{
public string Title { get; set; }
[Required]
public int CategoryId { get; set; }
//or
public int? CategoryId { get; set; }
}
控制器:
ViewBag.Categories = db.Categories.ToList();
看法:
@Html.DropDownListFor(m => m.CategoryId , new SelectList(ViewBag.Categories , "CategoryId ", "Title"),"")
@Html.ValidationMessageFor(model => model.CategoryId )
我有客户端验证
但在 Microsoft Default Scaffolding 中:
控制器:
ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId ", "Title");
看法:
@Html.DropDownList("CategoryId" ,"")
这是非常好的和干净的代码。但客户端验证不起作用。如何使用 Microsoft 默认的脚手架语法并且我有客户端验证