$ .ajax调用后的RedirectToAction MVC 3 [英] RedirectToAction MVC 3 after $.ajax call
问题描述
从我的角度来看,我正在通过$ .ajax发送一个JSON对象到我的控制器,以将其保存在数据库中. 如果一切成功,我想重定向到另一个操作,该操作将显示不同的视图.
From my view I am sending via $.ajax a JSON object to my controller to save it in the database. If all succeeded i want to redirect to another action which will show a diferent view.
如果我使用此代码:
return RedirectToAction("CreatePage", "Survey", new {id = question.PageId});
执行转到Survey控制器,该控制器返回一个视图,但未显示.
The execution goes to the Survey controller which returns a view but it is not shown.
我读了一些帖子,说不可能通过ajax重定向.
I have read some post which said that it is not posible to redirect via ajax.
到目前为止,我使用的解决方案是通过javascript这样重定向:
The solution I use so far is to redirect via javascript like this:
success: function (ret) {
window.location.href = "/Survey/CreatePage/" + $("#PageId").val();
}
尽管这始终有效,但有时我需要刷新CreatePage视图以显示最近进行的更改.
Although this always works, sometimes i need to refresh the CreatePage view to show the last changes made.
有什么想法可以更好地解决这个问题吗?
Any idea of how to solve this problem better?
预先感谢
推荐答案
正如mccow002所建议的,我真的不需要通过AJAX对该部分进行呼叫.在研究了建议的解决方案之后,我意识到我可以简单地以表格形式提交它.我之所以困惑,是因为我有一个保存并继续编辑和保存.对于保存并继续,我使用AJAX调用,但是对于提交表单的保存选项来说,是可以的.
As mccow002 suggested, I wasn't really needing to make the call via AJAX for that part. After studying the solutions suggested, i realized that i could simple submit it in a form. My confusion came because I have a save and continue editing and a save. For the save and continue I use the AJAX call, but for the save option with the form being submitted is ok.
非常感谢您的帮助.
这篇关于$ .ajax调用后的RedirectToAction MVC 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!