Domanda

Consider this setup:

public class SampleController : BaseController
{
    [MvcSiteMapNode(Title = "Super Title", Key = "Super", ParentKey = "topNav")]
    public ActionResult Index()
    {
        return View();
    }

    [MvcSiteMapNode(Title = "Sub Title", ParentKey = "Super")]
    public ActionResult SubAction(Guid id)
    {
        return View();
    }
}

When navigating to the SubAction the Html.MvcSiteMap().SiteMap.CurrentNode is always null. Except sometimes it works for a single Guid only (I suppose the first one requested)

Why?

Apart from this instance it works for all other actions in my project.

È stato utile?

Soluzione

I just had to add PreservedRouteParameters="true"

[MvcSiteMapNode(Title = "Sub Title", ParentKey = "Super", PreservedRouteParameters = "id")]
public ActionResult SubAction(Guid id)
{
    return View();
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top