MVC4 路由解析 同名Controller的解决方案

通常我们在MVC中通过Area建立子站的时候会有 controller名称重复的情况,这是后如何区分路由优先级,

我们知道 在Route对象中存在RouteValueDictionary 类型的DataTokens属性, 其中 Key 就是namespaces  Value就是我们配置命名空间字符串。

我们就会通过配置以命名空间。

    public class AppAreaRegistration : AreaRegistration
    {
        //命名空间
        string[] namespaces = { "MvcApp.Areas.App" };

        public override string AreaName
        {
            get
            {
                return "App";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "App_default",
                "App/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional },
                namespaces  //命名空间
            );
        }
         
    }

 

posted @ 2016-03-05 09:37  dragon.net  阅读(755)  评论(0编辑  收藏  举报