【发布时间】:2015-11-23 11:40:40
【问题描述】:
我正在使用 MvcSiteMapProvider 生成面包屑,但在将节点与新功能匹配时遇到问题。我们使用 MVC5 区域并使用最新的 MvcSiteMapProvider.MVC5 库。我们将i18n 与Resx 文件一起使用,我们的title 属性是键。我们的页面 URL 在发布后不会更改,因此请使用标准 XML 配置。
我们使用基于 MVC5 属性的路由。
List 动作是 Home 控制器和区域的默认动作,Store/ 路由也是如此。它工作正常,匹配成功。
Search 动作 Store/Search 路由不匹配节点。
配置
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd">
<mvcSiteMapNode controller="Dashboard" action="Index" title="Foobar" key="Bar">
<!-- quite a large file -->
<mvcSiteMapNode area="Store" controller="Home" action="List" title="SiteMap_DocumentStore_Home_List" preservedRouteParameters="page, itemsPerPage, msg">
<mvcSiteMapNode area="Store" controller="Home" action="Search" title="SiteMap_DocumentStore_Search" preservedRouteParameters="tags, page"/>
<!-- snip extra entries -->
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMap>
感谢我可以从List 的mvcSiteMapNode 子级中删除属性area 和controller。为了完整起见,我将它们留在这里。
家庭控制器
[RouteArea("Store")]
[Route("{action=list}")]
public class HomeController : Controller
{
[Route("{page?}/{itemsPerPage?}")]
public ActionResult List(int page = 1, int itemsPerPage = -1, string msg = "")
{}
[Route("Search/{tags?}/{page?}")]
public ActionResult Search(string tags = "", int page = 1)
{}
}
调查
我感觉这与 List 操作为 empty 的 MVC 路由有关。如果我把List的路由改成:
[Route("List/{page?}/{itemsPerPage?}")]
public ActionResult List(int page = 1, int itemsPerPage = -1, string msg = "")
{}
然后搜索节点将匹配,它的兄弟姐妹(我剪掉的)也会匹配
编辑 - 简化路由
我已删除控制器 [Route("{action=list}")] 的默认路由。问题依然存在。
【问题讨论】:
标签: c# .net model-view-controller url-routing mvcsitemapprovider