获取MVC3 Razor中的下拉列表值

时间:2011-06-17 09:06:57

标签: asp.net-mvc-3 drop-down-menu razor

当我点击提交按钮时,请帮助我获取控制器中下拉列表的选定值。

        My view is like
         @using (Html.BeginForm())
         {
            @foreach (var department in @Model)
            {
             items.Add(new SelectListItem
             {
                 Text = @department.DeptName,
                 Value = @department.DeptId.ToString()
             });                               

            }           
            @Html.DropDownList("deptID", items, "--Select One--", new { @style = width:160px" })                                               *              
            <input type="submit"   name="Filter" value="filter"  />
        }

    Please share if you are having any website link which explains about the dropdown list and its events in mvc3 Razor.

由于 圣

1 个答案:

答案 0 :(得分:3)

如果你有一个同名的参数

,MVC会为你处理绑定
public ActionResult MyAction(string deptID) 
{
    // whatever
}