0

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

我在主页和部分视图中使用以下 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");
                }
4

1 回答 1

-1

使用这个 java 库:

<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
于 2012-05-14T06:50:38.920 回答