2013-05-07 108 views
2

我在我的視圖中有一個下拉列表,它是通過模型填充的。我想將選定的值傳遞給
ajax鏈接。將下拉列表選定值傳遞給Ajax.ActionLink

 <select name="dd" id="dd"> 
       @foreach (var item in Model) 
       { 
        <option value="@item.cid" > 
          @item.cname</option> 
       } 
        </select> 


     @Ajax.ActionLink("Submit", "Someaction" , new { id = } , new     AjaxOptions { UpdateTargetId = "result" }) 


     <div id="result"></div> 

我應該如何路由選定的下拉菜單值?請幫助

回答

1

所選更改操作是客戶端事件,因此您無法使用幫助器處理此事件。但是你可以使用somethink這樣的:

<select name="dd" id="dd"> 
    @foreach (var item in Model) 
    { 
     <option value="@item.cid" >@item.cname</option> 
    } 
</select> 

腳本

$("#dd").change(function() { 
    var selectedVal = $(this).val(); 

    // in here you have ddl value 
    // you can pass this parameter with 
    // ajax and update your result div 

    $.ajax({ 
     url : 'Home/SomeAction', 
     data : { selected : selectedValue }, 
     ... 
     success : function(result){ 
      $("#result").html(result); 
     } 
    }); 
}); 

控制器

public ActionResult SomeAction(int selected) 
{ 
    // selected is the selected value of DDL... 

    //return Json/PartialView 
} 
相關問題