[英]Send Dropdown Selected Value from View to Controller using "DropDownListFor" in MVC
[英]MVC 3 Razor DropdownListFor - How to “filter” the view after value is selected
所以我建议在视图中创建一个DropDownListFor元素,这意味着创建一个名为
模型
class StudentModelView
。
我有两个属性。
StudentID{get;set;}
IEnumerable<SelectListItem> SelectPeopleList { get;set;}
我得到的列表用此代码很好地填充了
视图
@Html.DropDownListFor(x => x.StudentID, Model.SelectPeopleList,"--Select Students--", new Dictionary<string,object>{ {"class","dropdowns"},{"id","selectPeopleDDL"}})
//NEED A BUTTON TO SUBMIT
控制器
public ActionResult Index()
{
return View(new StudentModelView());
}
您可以使用jquery来完成所有操作,但这是几个指针:
您应该将过滤器包装为以下形式:
@using (Html.BeginForm("Home", "Index", FormMethod.Get))
{
@Html.DropDownListFor(x => x.StudentID, Model.SelectPeopleList,"--Select Students--", new Dictionary<string,object>{ {"class","dropdowns"},{"id","selectPeopleDDL"}})
<input type="submit" value="Go" />
}
提交按钮不是必须的,只要下拉列表的值发生变化,您都可以使用jquery进行提交
在您的控制器中:
public ActionMethod Index(int? studentID)
{
var model = new StudentModelView
{
StudentId = studentID,
SelectPeopleList=GetListFiltered(studentId)
}
return(model);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.