MVC中Html.DropDownListFor的联动更新
Controller中有:
List<SelectListItem> StepList = new List<SelectListItem>();
StepList.Add(new SelectListItem { Text = "公文起草", Value = "公文起草" });
StepList.Add(new SelectListItem { Text = "公文审核", Value = "公文审核" });
StepList.Add(new SelectListItem { Text = "公文审批", Value = "公文审批" });
StepList.Add(new SelectListItem { Text = "公文分发", Value = "公文分发" });
StepList.Add(new SelectListItem { Text = "公文归档", Value = "公文归档" });
ViewData["StepList"] = StepList;
UserService us = new UserService();
List<SelectListItem> items = new List<SelectListItem>();
foreach (var user in us.getUesrByRight(stepName))
{
items.Add(new SelectListItem { Text = user.UserName, Value = user.UserName });
}
ViewData["UserList"] = items;
View中有:
<%=Html.DropDownListFor(model => model.StepName, ViewData["StepList"] as
IEnumerable<SelectListItem>)%>
<%=Html.DropDownListFor(model => model.Operator, ViewData["UserList"] as
IEnumerable<SelectListItem>)%>
用意:
当选择<%=Html.DropDownListFor(model => model.StepName, ViewData["StepList"] as IEnumerable<SelectListItem>)%>的值之后,
将选中的值用 UserList 的查询,得出的结果集显示在<%=Html.DropDownListFor(model => model.Operator, ViewData["UserList"] as IEnumerable<SelectListItem>)%>的下拉列表中
求指导
------解决方案--------------------顶!顶!顶!顶!
------解决方案--------------------学习观摩
------解决方案--------------------DEMO