如何使用高效的 Route 和 ASP.NET Sitemap 对该导航场景进行建模?
我需要对以下场景进行建模,但我无法让它与 MvcSitemapProvider 一起使用(我认为我的问题也直接映射到默认的 SiteMapProvider)。我想让默认的面包屑控件能够正确处理我的动态数据。
我有一个产品
列表,这些产品按类别
分组,其中有一个父类别
- 父类别
- 类别
- 产品
我希望能够使用以下网址:
(1) /产品
(2) /产品/MainCategory
(3) /产品/MainCategory/类别
(4) /产品/MainCategory/类别/产品
显然我下面的解决方案不是最佳的。
Sitemap 中的 Products
节点没有ChildNodes,所以它们不会出现在我的菜单中。
我创建了一个中间对象,它添加了主要类别和类别,以便它们显示在我的菜单中。但这并不能解决问题,因为其他控件(面包屑)只是说我在 /Products 上。
我应该更改路线或更改站点地图定义吗?或者也许是其他什么?
我目前有以下路线:
- 2 条路线
1 表示 /Products、/Products/MainCategory 和 /Products/MainCategory/Category ->映射到 ProductsController.Index()
1 代表 /Products/MainCategory/Category/Product ->映射到 ProductsController.Product() - 站点地图中的 1 个条目
定义了dynamicParameters (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>
i need to model the following scenario, but I can't get it working with the MvcSitemapProvider (i think my problem also maps directly to the default SiteMapProvider). I want to get the default breadcrumbs control to work properly with my dynamic data.
I have a list of products
which are grouped by category
which have a parent-category
- ParentCategory
- Category
- Product
I want to be able to use the following url(s):
(1) /Products
(2) /Products/MainCategory
(3) /Products/MainCategory/Category
(4) /Products/MainCategory/Category/Product
Obviously my solution below is not optimal.
The Products
node in the Sitemap doesn't have ChildNodes, so they won't show up in my Menu.
I've created an intermediary object which adds the maincategories and categories so they show up in my menu. But this won't fix the problem as other controls (breadcrumbs) just say that I am on /Products.
Should I change my routes or change my sitemap definition? Or maybe something else?
I currently have the following:
- 2 Routes
1 for /Products, /Products/MainCategory and /Products/MainCategory/Category -> mapping to ProductsController.Index()
1 for /Products/MainCategory/Category/Product -> mapping to ProductsController.Product() - 1 entry in the Sitemap
with dynamicParameters defined (MainCategory;Category)
Global.asax Route definition:
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 = ""} _
)
I have the following entries in my sitemap:
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我目前正在使用自定义
SiteMapProvider
。我仍然在维护自定义路线,它们没有任何关系。I'm currently using a custom
SiteMapProvider
. I'm still also maintaining custom routes they are in no way related.