如何在@ Ajax.ActionLink routevalues对象中获取jQuery选择器结果?

时间:2011-10-25 19:48:49

标签: jquery ajax asp.net-mvc-3

我有以下@ Ajax.ActionLink代码:

@Ajax.ActionLink("Assign Ownership",
                 "AssignOwnership",
                 new
                 {
                   techLogCode = Model.TechLog.Code,
                   salesRepId = "",
                 },
                 new AjaxOptions
                 {
                   HttpMethod = "POST",
                   Confirm = "Are you sure you want to take ownership?",
                   OnSuccess = "reloadWindow",
                   OnFailure = "displayAjaxError"
                 })

我有一个id为所有者的下拉列表,我想将所选的值用作salesRepId。如何在@Ajax调用中获得该值?

这是我认为可行的jQuery。

$("#owner option:selected").val()

2 个答案:

答案 0 :(得分:3)

将您的操作链接放在div上并使用jQuery修改客户端的ajax链接。

    <div id="ajaxForm">    
          @Ajax.ActionLink("Assign Ownership",
             "AssignOwnership",
             new
             {
               techLogCode = Model.TechLog.Code,
               salesRepId = "",
             },
             new AjaxOptions
             {
               HttpMethod = "POST",
               Confirm = "Are you sure you want to take ownership?",
               OnSuccess = "reloadWindow",
               OnFailure = "displayAjaxError"
             })
   </div>


   <script type="text/javascript">
     $(document).ready(function(){
        $("#ajaxForm a").click(function (event) {
            $(this).attr('href', "/YourControllerName/AssignOwnership?techLogCode='Value1'&salesRepId= value2");
     });
     });

答案 1 :(得分:0)

为什么不将下拉列表放在AjaxForm中并将ActionLink更改为提交按钮?将techLogCode字段包含为隐藏字段