asp.net-mvc – RedirectToAction不工作

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – RedirectToAction不工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经在控制器发布后保存了一个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调用返回重定向响应时重定向,则由脚本重定向

原文链接:https://www.f2er.com/aspnet/253893.html

猜你在找的asp.Net相关文章