MVC RedirectToAction无法正常工作

时间:2016-08-26 10:33:04

标签: jquery angularjs asp.net-mvc

return RedirectToAction("Index", "Dashboard");

网址应为

  

http://localhost:6574/Dashboard/Index

但这显示

  

http://localhost:6574/Dashboard/

显示错误 enter image description here

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{*x}", new { x = @".*\.asmx(/.*)?" });
            routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "UserLogin", action = "Index", id = UrlParameter.Optional }
            );
        }

2 个答案:

答案 0 :(得分:2)

这可能是因为您的路线配置包含类似

的内容
routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

默认操作的位置为Index
这意味着,当你执行RedirectToAction("Index", "Dashboard");时,它会忽略索引,因为这已经是默认值。

答案 1 :(得分:1)

可能这个可以帮助你,在你的应用程序中设置web.config

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"></modules>
   <handlers>
    <remove name="UrlRoutingHandler"/>
   </handlers>
</system.webServer>

你也可以这样做,

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>