开发者

MVC SiteMap Provider - can anybody post a sample that works with dynamic nodes?

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


in father preservedRouteParameters="id"


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜