我已经使用RedirectToAction
在我完成了一个帖子到控制器并保存后,但网址没有改变,重定向似乎不起作用。我需要补充的是,当我调试时,重定向会输入控制器操作方法。它不会更改网址或导航到Index
视图...RedirectToAction不能正常工作
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 CALLS
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文章)。你能展示更多的代码吗? – 2010-02-08 21:37:41
aaaaahhh ....不知道。你是对的。它确实来自jQuery中的ajax文章,这意味着如果成功,我应该从那里重定向。没问题。把你的评论作为一个“答案”,我会标记当我证明它的作品,如果你喜欢 谢谢 – kurasa 2010-02-08 21:41:49