Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return Json will redirects to another view when Url specified

When you do return Json(...) you are specifically telling MVC not to use a view, and to serve serialized JSON data. Your browser opens a download dialog because it doesn't know what to do with this data.

i got the above information from below link

How to return Json object from MVC controller to view

when i give this below code in some action result

return Json(new { Url = "sep/employee"}

whether it will redirect to specified action ? how it redirects to the URl ?

for this case why i cant use return RedirectToAction("sep/employee").

how return Json code redirects to action which specified in the Url.

ex:

public ActionResult Index()
{
................................

return Json(new { Url = "sep/employee"}
}

public ActionResult employee()
{
....................
}

what is the difference b/s redirectaction and return Json

like image 931
SivaRajini Avatar asked Nov 28 '25 10:11

SivaRajini


1 Answers

You return the following line to an ajax success call

return Json(new { Url = "sep/employee"});    

you then need to specify where to redirect to the new page

success: function(result) {
        window.location.href=result.Url;
    }
like image 160
Nitin Varpe Avatar answered Dec 01 '25 16:12

Nitin Varpe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!