RedirectToAction不工作 [英] RedirectToAction not working
问题描述
我试图用一个 RedirectToAction
我做了后一篇文章到控制器和保存,但URL不会改变,重定向似乎并没有工作。我要补充的是,重定向确实进入了控制器的操作方法,当我调试。它不改变URL或浏览到首页
视图...
公开的ViewResult指数()
{
返回视图(指数,新TrainingViewModel());
}公众的ActionResult编辑()
{
//保存详细信息并返回列表
返回RedirectToAction(「指数」);}
我在做什么错了?
公共静态无效的RegisterRoutes(RouteCollection路线)
{
routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);
routes.IgnoreRoute({}资源的.js / {*} PATHINFO); ({?(* /)的favicon.ico(/.*)?图标= @}{*}图标,新)routes.IgnoreRoute; routes.MapRoute(
默认,//路线名称
{控制器} / {行动} / {ID},// URL带参数
新{控制器=家,行动=索引,ID =} //参数默认
);
}
// JQUERY通话
this.SynchValuesToReadOnly =功能(){
window.location的= $('#siteRoot')ATTR(HREF')+'网站/'。 }; this.OnSiteEdit =功能(){ //回发到服务器和更新评估的详情
VAR的选择= {
目标:'',
类型:'后',
网址:'/网站/编辑',
beforeSubmit:othis.validate,
成功:othis.SynchValuesToReadOnly
}; $('#uxSiteForm')ajaxSubmit会(期权)。
};
在code你看是正确的。我的胡乱猜测是,你没有做一个标准的POST(例如,重定向不以AJAX岗位工作)。
浏览器会忽略一个重定向响应AJAX POST。这是给你的脚本重定向,如果你需要在一个AJAX调用返回一个重定向响应重定向。
I tried using a RedirectToAction
after I have done a post to the controller and saved but the URL does not change and the redirect does not seem to work. I need to add that the redirect does enter the controller action method when I debug. It does not change the URL or navigate to the Index
view...
public ViewResult Index()
{
return View("Index",new TrainingViewModel());
}
public ActionResult Edit()
{
//save the details and return to list
return RedirectToAction("Index");
}
what am I doing wrong ?
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);
};
The code you show is correct. My wild guess is that you're not doing a standard POST (e.g., redirects don't work with an AJAX post).
The browser will ignore a redirect response to an AJAX POST. It's up to you to redirect in script if you need to redirect when an AJAX call returns a redirect response.
这篇关于RedirectToAction不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!