调用下拉ajax请求的asp.net mvc

时间:2022-12-04 17:06:32

ok i have a record grid with different records

我有一个不同记录的记录网格

plus i have a dropdown as column as well (which ought to go and just save the value i have selected and come back on the same stage , i have to send some id as well) . how to achieve this . form is at the movement submitting in my code.

另外,我还有一个作为列的下拉菜单(应该去保存我选择的值,然后回到相同的舞台上,我也必须发送一些id)。如何实现这一点。表单在提交我的代码的运动中。

   <% using (Ajax.BeginForm("SaveStatus", new AjaxOptions { OnSuccess = "jobStatusChanged" }))
              {%>
              <%=Html.Hidden("JobFormMain",item.int_JobFormMain) %>
        <%:  Html.DropDownList("SelectedItem", JobHelper.GetSelectStatus(item.int_JobFormMain) as IEnumerable<SelectListItem>, new { onchange = "this.form.submit();" })%>
        <% } %>

 public ActionResult SaveStatus(int? page,FormCollection form, int id = 0)
    {    
   return View()
   }

1 个解决方案

#1


2  

I would use jquery to bind to the dropdown's change event, and then post the value to your controller action. You can assign a class to the dropdown to make it easy to select with jquery.

我将使用jquery绑定到下拉菜单的更改事件,然后将值发布到控制器动作。您可以将一个类分配给下拉菜单,以便使用jquery轻松选择。

<%= Html.DropDownList("SelectedItem", JobHelper.GetSelectStatus(item.int_JobFormMain) as IEnumerable<SelectListItem>, new { @class = "SelectedItemDropDown" })%>

<script type="text/javascript">
    $(document).ready(function()
    {
        $(".SelectedItemDropDown").change(function()
        {
            $.post("controller/SaveStatus", { id : $(this).val() });
        }
    }
</script>

#1


2  

I would use jquery to bind to the dropdown's change event, and then post the value to your controller action. You can assign a class to the dropdown to make it easy to select with jquery.

我将使用jquery绑定到下拉菜单的更改事件,然后将值发布到控制器动作。您可以将一个类分配给下拉菜单,以便使用jquery轻松选择。

<%= Html.DropDownList("SelectedItem", JobHelper.GetSelectStatus(item.int_JobFormMain) as IEnumerable<SelectListItem>, new { @class = "SelectedItemDropDown" })%>

<script type="text/javascript">
    $(document).ready(function()
    {
        $(".SelectedItemDropDown").change(function()
        {
            $.post("controller/SaveStatus", { id : $(this).val() });
        }
    }
</script>

相关文章