【发布时间】:2016-07-05 05:00:07
【问题描述】:
我正在使用@Html.MvcSiteMap().SiteMapPath() 构建面包屑路径。
我有两个控制器,一个是从 DealsContorllerBase 类继承的 DealsController。 这两个类都有自己的 Index() 方法,其中子类的 Index() 覆盖了父类的 Index()。 在我的 Mvc.sitemap 中:
<mvcSiteMapNode title="Deals" controller="Deals" action="Index" >
<mvcSiteMapNode title="Deal" controller="Deals" action="ShowSpecificDeal" />
</mvcSiteMapNode>
在RegisterRoute函数中:
...
routes.MapRoute(
"Deals", // Route name
"Deals", // URL with parameters
new { controller = "Deals", action = "Index" }, // Parameter defaults
new[] { "InvestX.UI.Web", "InvestX.UI.Controllers" } // namespaces
);
...
在“InvestX.UI.Web”项目中定义的 DealsController 和在“InvestX.UI.Controllers”项目中定义的 DealsControllerBase。
整个异常如下:
模棱两可的控制器。找到多种控制器类型 '交易控制器'。匹配的类型有:
InvestX.UI.Web.Controllers.DealsController InvestX.UI.Controllers.DealsControllerBase`1
考虑通过添加控制器来缩小搜索范围 命名空间到 ControllerBuilder.Current.DefaultNamespaces 或 通过将命名空间添加到 areaNamespacesToIgnore 来排除命名空间 ControllerTypeResolverFactory的参数。
我知道如果 DealsController 不是从 DealsControllerBase 继承而只使用 DealsController,一切都会好起来的。 异常是由要采取的 Index() 操作引起的:DealsController 的或 DealsControllerBase 的。 我的问题是 mvcSiteMapNode 如何处理这样的父/子控制器层次结构?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-5 mvcsitemapprovider asp.net-mvc-sitemap