将选定值的下拉列表传递给更改选定项目的控制器
Pass Dropdownlistfor selected value to controller on selected item changed
尝试将所选值(在本例中为 studentid)传递给 BeginForm。
查看
@using (Html.BeginForm("DDSubmit", "Home",new { id=Model.studentID}, FormMethod.Post))
{
@Html.DropDownListFor(m => m.studentID, Model.DDList, "Please Select",new { onchange = "this.form.submit();" })
}
控制器动作
public ActionResult DDSubmit(int id)
{
var info = (from r in entity.STUDENTS where r.Student_Id == id select r).ToList();
return View(info);
}
型号
public class DDModel
{
public List<SelectListItem> DDList { get; set; }
public int studentID { get; set; }
public string studentName { get; set; }
}
终于想通了
查看
@using (Html.BeginForm("DDSubmit", "Home", FormMethod.Post))
{
@Html.DropDownListFor(m => m.studentID, Model.DDList, "Please Select",new { onchange = "this.form.submit();" })
}
动作
public ActionResult DDSubmit(DDModel ddlist)
{
int id = ddlist.studentID;
var info = (from r in entity.STUDENTS where r.Student_Id == id select r).ToList();
return View(info);
}
尝试将所选值(在本例中为 studentid)传递给 BeginForm。
查看
@using (Html.BeginForm("DDSubmit", "Home",new { id=Model.studentID}, FormMethod.Post))
{
@Html.DropDownListFor(m => m.studentID, Model.DDList, "Please Select",new { onchange = "this.form.submit();" })
}
控制器动作
public ActionResult DDSubmit(int id)
{
var info = (from r in entity.STUDENTS where r.Student_Id == id select r).ToList();
return View(info);
}
型号
public class DDModel
{
public List<SelectListItem> DDList { get; set; }
public int studentID { get; set; }
public string studentName { get; set; }
}
终于想通了
查看
@using (Html.BeginForm("DDSubmit", "Home", FormMethod.Post))
{
@Html.DropDownListFor(m => m.studentID, Model.DDList, "Please Select",new { onchange = "this.form.submit();" })
}
动作
public ActionResult DDSubmit(DDModel ddlist)
{
int id = ddlist.studentID;
var info = (from r in entity.STUDENTS where r.Student_Id == id select r).ToList();
return View(info);
}