MVC SiteMap Provider - 任何人都可以发布使用动态节点的示例吗?
这是一个非常简单的场景:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在父亲中servedRouteParameters =“id”
in father preservedRouteParameters="id"
我想通了。没有带有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)
topublic ActionResult Index(int id)
and everything began working...-Stan