MVC SiteMap Provider - 任何人都可以发布使用动态节点的示例吗?

发布于 2024-12-01 10:18:57 字数 1266 浏览 1 评论 0原文

这是一个非常简单的场景:

public class StockItemController : Controller
{
    public ActionResult Index(int categoryId)
    {
    /// ...
    }
}

示例路线:

/StockItem?categoryId=1 // 应该是“Beverages” /StockItem?categoryId=1 // 应该是“Shoes”

这是缩写的站点地图:

  <mvcSiteMapNode title="Home" controller="Home" action="Index">    
  <mvcSiteMapNode title="Template" action="Index" controller="StockItem" dynamicNodeProvider="uTani.UI.Common.BreadCrumbCategoryProvder, Store.UI" />    

和类的一部分:

public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
    {
        foreach (Category category in _repository.GetCategories())
        {
            string key = "Category" + category.Id;
            string title = category.DescriptionRU;
            DynamicNode node = new DynamicNode(key, title);
            node.RouteValues.Add("categoryId", category.Id);

            yield return node;
        }           
    }

这一切的作用是使用 @Html.MvcSiteMap().Menu() 正确生成站点菜单,但问题是 @Html.MvcSiteMap()。 SiteMapPath() (面包屑)始终显示第一个动态节点,无论路线是什么...

我不知道我在这里缺少什么,并且对此没有足够的文档...有人有吗一个样本或者可以指出我做错了什么?

谢谢,

-斯坦

It is a very simple scenario:

public class StockItemController : Controller
{
    public ActionResult Index(int categoryId)
    {
    /// ...
    }
}

Sample routes:

/StockItem?categoryId=1 // should be "Beverages"
/StockItem?categoryId=1 // should be "Shoes"

Here is the abbreviated site map:

  <mvcSiteMapNode title="Home" controller="Home" action="Index">    
  <mvcSiteMapNode title="Template" action="Index" controller="StockItem" dynamicNodeProvider="uTani.UI.Common.BreadCrumbCategoryProvder, Store.UI" />    

and the part of the class:

public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
    {
        foreach (Category category in _repository.GetCategories())
        {
            string key = "Category" + category.Id;
            string title = category.DescriptionRU;
            DynamicNode node = new DynamicNode(key, title);
            node.RouteValues.Add("categoryId", category.Id);

            yield return node;
        }           
    }

What this all does is generates the site menu correctly with @Html.MvcSiteMap().Menu() but the problem is that @Html.MvcSiteMap().SiteMapPath() (breadcrumb) always shows the very first dynamic node no matter what the route is...

I don't know what I am missing here and there isn't enough documentation on this.. Does anyone has a sample or can point out what I am doing wrong?

Thanks,

-Stan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

折戟 2024-12-08 10:18:57

在父亲中servedRouteParameters =“id”

in father preservedRouteParameters="id"

明明#如月 2024-12-08 10:18:57

我想通了。没有带有categoryId参数的路由,链接为“/StockItem?categoryId=1”。这有效,但抛弃了站点地图,因为它期望“/StockItem/Category/1”,并且由于没有人,所以它返回第一个节点。我只是更改了 public ActionResult Index(int CategoryId)public ActionResult Index(int id),一切都开始工作......-

Stan

I figured it out. There was no route with the categoryId parameter and the links were "/StockItem?categoryId=1". That worked but was throwing site map off because it expected "/StockItem/Category/1" and since there was no one, it was returning the first node.. I simply changed public ActionResult Index(int categoryId) to public ActionResult Index(int id) and everything began working...

-Stan

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文