加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – RedirectToAction不工作

发布时间:2020-12-15 18:48:06 所属栏目:asp.Net 来源:网络整理
导读:我已经在控制器发布后保存了一个RedirectToAction,但URL并没有改变,重定向似乎不起作用。我需要补充说,当我调试时,重定向会进入控制器的action方法。它不会更改URL或导航到索引视图… public ViewResult Index() { return View("Index",new TrainingView
我已经在控制器发布后保存了一个RedirectToAction,但URL并没有改变,重定向似乎不起作用。我需要补充说,当我调试时,重定向会进入控制器的action方法。它不会更改URL或导航到索引视图…
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帖子)。

浏览器将忽略对AJAX POST的重定向响应。如果您需要在AJAX调用返回重定向响应时重定向,则由脚本重定向。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读