Quantcast
Channel: Internet Explorer Web Development forum
Viewing all articles
Browse latest Browse all 3527

Ajax Post and MVC calls the HttpGet ActionResult Method.

$
0
0

I am positing a form using Ajax JQuery. The following pieces of code are posting the data to the server. On ajax success, I am calling windows.location.reload to display the updated data. Everything works fine till here. However, after ajax success MVC calls its action method that wipes out every changes that are done by the indow.location.reload(true). Why MVC is calling Action Result method. I have other MVC controller page that has the exactly same logic but it is not calling the MVC action result method after ajax success call. Please advice.


$.ajax({
                        url: '@Url.Action("Index", "WarehouseInventory")',
                        data: JSON.stringify({ "formData": formData, "locationId": locationId }),
                        type: 'POST',
                        traditional:true,
                        dataType: 'json',
                        contentType: "application/json",
                        success: function (result) {
                            toastr.success('All information have been saved successfully!.');
                            setTimeout(function () {
                               GetInventories(locationId); //populating jquery datatable here
                               window.location.reload(true); // refreshing page here
                            },2000);
                        },
                     error: function (xhr, errorType, exception) {

                         OnError(xhr, errorType, exception);
                        },
                        complete: function (result) {
                           $("#grid").find("input").attr("disabled", "disabled");
                        }
                 });

[HttpGet]
public async Task<ActionResult> Index(int? LocationId = null)  // Why this method is called after ajax post.
 {
            await TestMethod(LocationId);
           return View();
}

                       

Viewing all articles
Browse latest Browse all 3527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>