2011-06-17 95 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