2015-08-03 66 views
0

场景: 我有3个地区named- 专辑歌手音乐 现在,每一个领域都具有相同名称的控制器。例如,每个区域都有LoginController。如何在使用asp.net mvc中的区域时配置路由?

现在目前我得到以下异常

多种类型的发现一致评为控制器“登陆” 可能发生这种情况如果服务这个请求没有指定命名空间的路线搜索控制器匹配请求。 如果是这种情况,请通过调用带有'namespaces'参数的'MapRoute'方法的重载来注册此路由。

这是自动生成由Visual Studio配置上创建区

public override string AreaName 
    { 
     get 
     { 
      return "Albums" 
     } 
    } 

    public override void RegisterArea(AreaRegistrationContext context) 
    { 
     context.MapRoute(
      "Albums_Default" 
      "Client/{controller}/{action}/{id}", 
      new { action = "Index", id = UrlParameter.Optional } 
     ); 
    } 

这是我在RoutesConfig.cs

routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
      namespaces: new[] { "Application_Name" } 
     ); 

现在INTIAL配置如何配置路由,如果没有URL中的任何修改,将呈现所需的视图。

回答

1

请尝试这一个:

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

     routes.MapRoute(
     "Default",            // Route name 
     "{controller}/{action}/{id}",       // URL 
     new { controller = "Home", action = "Index", id = "" }, // Defaults 
     new[]{"AreasDemoWeb.Controllers"}      // Namespaces 
    ); 
    } 

Help Link 1

Help Link2