【问题标题】:MVC custom routing issueMVC 自定义路由问题
【发布时间】:2013-12-04 10:40:14
【问题描述】:

我正在使用 MVC 5,并尝试在 Route.Config (即 Home)中创建自定义路由,但是当我运行应用程序时,它会将我直接带到我不想要的自定义路由。默认是登录,成功应该会导致仪表板/主页(控制器/动作),但我只想使用主页(仅限动作名称)。非常感谢

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        //---In order to use only Action Title in URL--//
        routes.MapRoute(
            "Home",
            "{action}/{id}",
             new { controller = "Dashboard", action = "Home", id = UrlParameter.Optional }
            );

        //-----default routing---//
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Admin", action = "Login", id = UrlParameter.Optional }
        );
    }
}

【问题讨论】:

    标签: c# asp.net-mvc


    【解决方案1】:

    试试这个:

       routes.MapRoute(
            "Home",
            "Home/{id}",
             new { controller = "Dashboard", action = "Home", id = UrlParameter.Optional }
            );
    

    【讨论】:

      【解决方案2】:

      如果你想在动作中导航到不同控制器的新动作,那么你必须在下面提到。

      如果您想从登录名导航到主页,那么您实际上不必更改路线。在成功调用的登录操作中

      RedirectToAction(String, String)    Redirects to the specified action using the action name and controller name.
      

      提供

      RedirectToAction("Home", "Dashboard");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多