ASP.NET MVC5路由实践RouteConfig

RouteConfig.cs

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
     //如请求http://localhost:50836/test,由ZJ.MVC5.Platform.Controllers.TestController.cs 响应请求 
        routes.MapRoute(
            name: "Default2",
            url: "test/{action}",
            defaults: new { controller = "Test", action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "ZJ.MVC5.Platform.Controllers" }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
        ////defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        //defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional },
        ////defaults: new { controller = "Test", action = "ShopPic", id = UrlParameter.Optional },
        //namespaces: new string[] { "ZJ.MVC5.Platform.Areas.Movie" } //影片管理
        //).DataTokens.Add("Area", "Movie");

        defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional },
        namespaces: new string[] { "ZJ.MVC5.Platform.Areas.QuestionBank" }
        ).DataTokens.Add("Area", "QuestionBank");
    }
}

 

posted @ 2020-08-21 14:27  轴轴  阅读(311)  评论(0编辑  收藏  举报