MVC3 Ajax表单多次提交

时间:2012-05-14 06:37:11

标签: ajax asp.net-mvc-3

我在我的页面中使用 Ajax表单,我在第一页中有几个AJAX表单 - (Customers.cshtml),另一个是< strong> PARTIAL VIEW(_customers.cshtml)。当我提交部分视图时。此PARTIAL VIEW 多次提交**

我在主页面和部分视图中使用以下Ajax脚本


 <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")"

我的代码如下:

    Customers.cshtml replaces the div tag with id="customers"
---------------------------------------------------------------------

    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> 

    <script src="@Url.Content("~/Scripts/json2.js")" type="text/javascript"></script>
    @if (false)
    { <script src="~/Scripts/jquery-1.7.1-vsdoc.js" type="text/javascript"></script> }
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>



     @using (Ajax.BeginForm("Action1", "Controller1", new AjaxOptions() { InsertionMode = InsertionMode.Replace, UpdateTargetId = "customers" }))
    {
                        @Html.AntiForgeryToken()
        <input type="submit"  class="t-button t-state-default"/>
    }



    <div id="customers"> </div>
    <div id="Orders"></div>

    <div id="customers> tag is replaced with a partial view which has another AJAX FORM




    **_customers.cshtml replaces the div tag with id="orders"**
--------------------------------------------------------

     <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>

    @using (Ajax.BeginForm("Action2", "Controller1", new AjaxOptions() { InsertionMode = InsertionMode.Replace, UpdateTargetId = "Orders" }, new { id = "formupdate" }))
    {
               @Html.AntiForgeryToken()
    <input type="submit"  class="t-button t-state-default"/>

    }


    Now when I try to submit the  **_customers.cshtml** , it is submitting more than once
<br/>
           Controller
            -----------------------------------------------
         [HttpPost]
         public ActionResult Action1()
                {          

                    return PartialView("_customers");
                }
         [HttpPost]
         public ActionResult Action2()
                {          

                    return PartialView("_Shipping");
                }

1 个答案:

答案 0 :(得分:-1)

使用此java库:

<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>