将选定值的下拉列表传递给所选项目的控制器已更改

时间:2017-01-25 06:33:17

标签: asp.net asp.net-mvc asp.net-mvc-4 asp.net-mvc-3

尝试将在本例中为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; }
}

1 个答案:

答案 0 :(得分:0)

终于想通了

视图

 @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);            
    }