【发布时间】:2010-01-07 16:36:32
【问题描述】:
我需要为以下场景建模,但我无法让它与 MvcSitemapProvider 一起使用(我认为我的问题也直接映射到默认的 SiteMapProvider)。我想让默认的面包屑控件与我的动态数据一起正常工作。
我有一个products 列表,这些列表按category 分组,其中parent-category 有一个parent-category
- 父类
- 类别
- 产品
我希望能够使用以下网址:
(1) /Products
(2) /Products/MainCategory
(3) /Products/MainCategory/类别
(4) /Products/MainCategory/Category/Product
显然我下面的解决方案不是最优的。
站点地图中的Products 节点没有子节点,因此它们不会出现在我的菜单中。
我创建了一个中间对象,它添加了主类别和类别,以便它们显示在我的菜单中。但这并不能解决问题,因为其他控件(面包屑)只是说我在 /Products 上。
我应该更改路线还是更改站点地图定义?或者是别的什么?
我目前有以下:
-
2 条路线
1 用于 /Products、/Products/MainCategory 和 /Products/MainCategory/Category -> 映射到 ProductsController.Index()
1 代表 /Products/MainCategory/Category/Product -> 映射到 ProductsController.Product() -
站点地图中有 1 个条目
定义了动态参数 (MainCategory;Category)
Global.asax 路由定义:
routes.MapRoute( _
"Product", _
"Products/{MainCategoryName}/{CategoryName}/{ProductName}", _
New With {.controller = "Products", .action = "Product"} _
)
routes.MapRoute( _
"Products", _
"Products/{MainCategoryName}/{CategoryName}", _
New With {.controller = "Products", .action = "Index", .GroupName = "", .CategoryName = ""} _
)
我的站点地图中有以下条目:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<mvcSiteMapNode controller="Home" action="Index" title="Home" description="Homepage">
<mvcSiteMapNode controller="Products" action="Index" title="Products" description="" isDynamic="true" dynamicParameters="MainCategoryName;CategoryName" />
</mvcSiteMapNode>
</siteMap>
【问题讨论】:
标签: asp.net-mvc sitemapprovider mvcsitemapprovider