0

I am using Ajax Form in my page , I have couple of AJAX forms in the page one --(Customers.cshtml) , and the other comes as PARTIAL VIEW (_customers.cshtml). When I Submit the Partial View. This PARTIAL VIEW IS submitting multiple times**

I am using the following Ajax script in main page and also in Partial View


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

My code follows like this :

    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");
                }
Brad
  • 229
  • 2
  • 4
  • 12
  • See answer in [this link][1] [1]: http://stackoverflow.com/questions/4869583/asp-net-mvc-form-loaded-via-ajax-submits-multiple-times – kma1975 Sep 18 '13 at 05:56

1 Answers1

-1

Use this java libraries:

<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
Nildarar
  • 802
  • 1
  • 8
  • 17