C# MVC 3 Razor DropdownListFor-如何;“过滤器”;选择“后视图”值
所以我采纳了一些建议,在我的视图中创建一个DropDownListFor元素,这意味着创建一个名为 型号C# MVC 3 Razor DropdownListFor-如何;“过滤器”;选择“后视图”值,c#,asp.net-mvc-3,razor,C#,Asp.net Mvc 3,Razor,所以我采纳了一些建议,在我的视图中创建一个DropDownListFor元素,这意味着创建一个名为 型号 class StudentModelView 我有两个属性 StudentID{get;set;} IEnumerable<SelectListItem> SelectPeopleList { get;set;} 我需要什么样的按钮才能将其发布 发布后,如何更新视图以显示新的筛选列表?我是缺少一个POST控制器还是只是ajax?最好的方法是什么 您可以使用jquery完成这一切
class StudentModelView
我有两个属性
StudentID{get;set;}
IEnumerable<SelectListItem> SelectPeopleList { get;set;}
您可以使用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" />
}
如果您所做的只是过滤视图,那么您应该尝试GET而不是POST。+1,我使用类似的方法,但让jquery调用一个操作,返回部分视图,然后将其附加到我页面上的一个div,使加载看起来更流畅:),请参见此处[link]@RobJohnson,这些过滤器中的大多数只是在我的应用程序库中使用ajax渲染的!我还为负载使用了局部视图。我只是不想通过添加另一个变量来扰乱解释。
public ActionResult Index()
{
return View(new StudentModelView());
}
@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" />
}
public ActionMethod Index(int? studentID)
{
var model = new StudentModelView
{
StudentId = studentID,
SelectPeopleList=GetListFiltered(studentId)
}
return(model);
}