【发布时间】:2011-07-11 13:59:51
【问题描述】:
控制器
var productList = Enumerable.Range(1, 80).Select(
x => new SelectListItem { Value = x.ToString(), Text = x.ToString() }
);
ViewData["products"] = new SelectList(productList.ToList(), "Value", "Text");
查看
<%: Html.DropDownList("products", ViewData["products"] as SelectList, "--select--")%>
<%: Html.ValidationMessage("products", "Please Select the Product from the List")%>
//This doesnt works on (ModelState.IsValid) I know the dropdown list data is coming
//from the view data not model , thats why model doesnt validate the particular dropdown
//list while it validates other fields which are linked to model,
//Just want to know, how can i validate the above dropdownlist
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-2 validation asp.net-mvc-3