【问题标题】:How to model this navigation scenario with efficient Route and ASP.NET Sitemap?如何使用高效的 Route 和 ASP.NET Sitemap 对这种导航场景进行建模?
【发布时间】: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


    【解决方案1】:

    我目前正在使用自定义SiteMapProvider。我仍在维护与它们毫无关系的自定义路线。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-15
      • 2022-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多