Ajax调用后返回视图 [英] return view after ajax call
本文介绍了Ajax调用后返回视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jquery进行异步调用后,如何返回特殊视图?
after an async call with jquery how can I return a particolar 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>
这是我的控制器操作:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Run(string nome, string cognome)
{
return View("Result");
}
无法显示视图结果" 怎么样?
can not display view "Result" How?
推荐答案
您不能从异步调用中返回View
.
Ajax请求的目的是避免执行整个页面周期.
You can not return a View
from an asynchronous call.
An ajax request is meant to avoid doing an entire page cycle.
如果您要返回新的View
,则只需返回POST
.
You should just do a POST
back if you want a new View
to be returned.
另一个选择是在ajax调用成功后进行回调,并将window.location
设置为新的View
,以便页面将GET
设置为新的View
.
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
.
这篇关于Ajax调用后返回视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文