Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to return JSON and at the same time redirect to a page or return view from the same action invoked through ajax call from view.

What I have tried:

return JSON and at the same time redirect to a page or return view from the same action
Posted
Updated 11-Nov-16 2:16am

A request can only have one response so if an action returns JSON it can't return anything else. If you want to redirect to a page after you can return that url in the json also and once the json is processed you can read the url to redirect to.

Ultimately you'll need to explain what it is you're trying to achieve to see if someone has the solution.
 
Share this answer
 
You can return the json data from the action and in the success method of the ajax call just redirect it to relevant action
JavaScript
$.ajax({
           type: "post",
           dataType: "json",
           url: 'controller/action',
           data: { },
           success: function (jsonData) {
               window.location.href =  '@Url.Action("ActionName", "ControllerName")'
           }
       });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900