2015-08-14 62 views
0

让我们说我有这样的主控制器在我的MVC应用程序:RouteArea和“多控制器类型中发现匹配的URL是”错误

[RouteArea("Blog")] 
public class PageController : BaseAppController 
{ 
} 

[RouteArea] 
// Called on mydomain/Blog 
// and also called on mydomain/ 
public class BaseAppController : Controller 
{ 
    [Route] 
    public ActionResult Index() 
    { 
     return Content("this is the index file form the main controller"); 
    } 
} 

,因为它的预期,我会得到在mydomain/BlogIndex行动,但由于某种原因,我也在我的/中得到它,这与我从另一个控制器获得的另一种观点相冲突。 我没有任何默认设置为我的任何根:

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
    routes.LowercaseUrls = true; 
    routes.MapMvcAttributeRoutes(new CustomDirectRouteProvider()); 

} 

任何想法是什么问题?

+0

什么是CustomDirectRouteProvider? –

+0

@AlexArt。在那里启用控制器继承。检查它在这里:http://stackoverflow.com/questions/19989023/net-webapi-attribute-routing-and-inheritance – Yar

+0

@霍曼 - 根据评论下面的答案,许多人无法得到它的工作。此外,答案是** WebAPI **,而不是** MVC **。 – NightOwl888

回答

0

它来了我需要使基类为abstract,因为它在层次结构的顶部,所以不会有任何其他实例可以被其他视图访问。 所以在上例中:

[RouteArea("Blog")] 
public class PageController : BaseAppController 
{ 
} 

[RouteArea] 
// is going to be called just on mydomain/Blog and not on mydomain/ 
public abstract class BaseAppController : Controller 
{ 
    [Route] 
    public ActionResult Index() 
    { 
     return Content("this is the index file form the main controller"); 
    } 
} 
相关问题