2011-06-17 20 views
1

当我单击提交按钮时,请帮助我获取控制器中下拉列表的选定值。在MVC3 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. 

感谢 圣

+2

参数为您结合MVC交易做正确的方式http://stackoverflow.com/questions/4674033/mvc-3-layout-page-razor-template-and-dropdownlist/4678786#4678786 – Tsar 2011-06-17 09:20:59

+0

这跟剃刀真的没什么关系 – fearofawhackplanet 2011-06-17 09:30:58

+0

谢谢不好显示名称我会去做:) – san 2011-06-17 09:58:10

回答

3

用,如果你有相同的名称

public ActionResult MyAction(string deptID) 
{ 
    // whatever 
} 
+0

谢谢... int selectedValue = Convert.ToInt32(的Request.Form [“部门ID”]);也是可行的... – san 2011-06-17 09:48:36

+0

如何在不使用提交按钮的情况下选择下拉值时如何调用控制器功能? – alice7 2012-04-02 17:29:29

+0

@ alice7你需要使用JavaScript(或像jQuery这样的库,使其更简单) – fearofawhackplanet 2012-04-04 10:56:45