简体   繁体   中英

JQuery Ajax post not redirecting when ActionResult returned from MVC controller

I am attempting to post data from a method to an MVC controller that returns an action result, and have my site redirect to the correct view. The code I am attempting to use is below.

function KoJqRedirect(item, url, async) {
$.ajax({
    type: "Post",
    contentType: "application/json",
    data: ko.toJSON(item),
    async: async,
    url: url,
    success: function () { return false; }
});

}

The controller is posted to correctly and returns the view, the problem is that the page is not displayed. How would i go about getting this page to display when returned to the success function?

If you want to show html returning from controller action then do as :

function KoJqRedirect(item, url, async) {
  $.ajax({
   type: "post",
   contentType: "application/json",
   data: ko.toJSON(item),
   datatype :'html', //give datatype here
   async: async,
   url: url,
   success: function (data) { 
     $("#div1").html(data); //provide target div id here 
   }
 });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM