【发布时间】:2010-02-08 21:35:43
【问题描述】:
在向控制器发布并保存后,我尝试使用RedirectToAction,但 URL 没有更改,并且重定向似乎不起作用。我需要补充一点,当我调试时,重定向确实进入了控制器操作方法。它不会更改 URL 或导航到 Index 视图。
public ViewResult Index()
{
return View("Index", new TrainingViewModel());
}
public ActionResult Edit()
{
// save the details and return to list
return RedirectToAction("Index");
}
我做错了什么?
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.js/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
jQuery 调用:
this.SynchValuesToReadOnly = function() {
window.location = $('#siteRoot').attr('href') + 'Sites/';
};
this.OnSiteEdit = function() {
// post back to the server and update the assessment details
var options = {
target: '',
type: 'post',
url: '/Site/Edit',
beforeSubmit: othis.validate,
success: othis.SynchValuesToReadOnly
};
$('#uxSiteForm').ajaxSubmit(options);
};
【问题讨论】:
-
您显示的代码是正确的。我的疯狂猜测是您没有执行标准 POST(例如,重定向不适用于 AJAX 帖子)。你能显示更多代码吗?
-
aaaaahhh....不知道。是的你是对的。它确实来自 jquery 中的 ajax 帖子,这意味着如果成功,我应该从那里重定向。没问题。将您的评论作为“答案”提出,如果您愿意,我会在证明它有效时标记谢谢
标签: asp.net-mvc