return view after ajax call
15,173
Solution 1
You can not return a View
from an asynchronous call.
An ajax request is meant to avoid doing an entire page cycle.
You should just do a POST
back if you want a new View
to be returned.
The other option would to be have a callback upon success of the ajax call and set the window.location
to the new View
so the page does a GET
to the new View
.
Solution 2
Use a call back function that will redirect the user once the AJAX returned.
ajax(/*suff*/).success(callbackFuntion);
And then in your callback
function callbackFuntion(){
window.location = "www.google.com";
}
Related videos on Youtube
Author by
user2336491
Updated on June 12, 2022Comments
-
user2336491 about 2 years
after an async call with jquery how can I return a particolar view?
this my caller view:
<script type="text/javascript"> function Run() { $.ajax({ type: "POST", cache: false, url: "/Home/Run", data: $("#form_run").serializeArray(), dataType: "json" }); } </script> <form action="javascript:return true;" method="post" id="form_run"> <input type="text" id="nome" name="nome" /> <input type="text" id="cognome" name="cognome" /> <input type="submit" name="submit" value="Run" onclick="Run();" /> </form>
this my controller action:
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Run(string nome, string cognome) { return View("Result"); }
can not display view "Result" How?
-
SLaks about 11 yearsThat defeats the purpose of AJAX.
-