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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With