It doesnt remember dynamic parameters?

Nov 18, 2009 at 6:51 PM

Hi

It first, thx for ur good job. This SiteMap provider works almost as good as i expected :o).

But i have one question. If it does remember the Title of sitemap node, why does it not remember the dynamicParameters? I have to explicit set the parameters to SiteMap.CurrentNode, then it remember it.

Am I missing something? Any settings?

Sorry for my dumb quiestion.

 

PS: The workaround is to explicit set in every controller action dynamic parameters for current siteMapNode, but is pretty annyoning.

Very thx for answer.

Nov 18, 2009 at 10:12 PM

well, i add this code to main base controller and now it works exactly how i expected :o)

protected override void OnActionExecuted(ActionExecutedContext filterContext)
  {
  base.OnActionExecuted(filterContext);

  //add sitemap routing

  MvcSiteMapNode ms = SiteMap.CurrentNode as MvcSiteMapNode;

  if (ms == null)
  return;

  if (!(filterContext.Result is ViewResult) || !ms.IsDynamic || 
  ms.DynamicParameters == null || ms.DynamicParameters.Count == 0)
  return;  
   
  foreach(string s in ms.DynamicParameters)
  {
  if (filterContext.RouteData.Values.ContainsKey(s) && !ms.RouteValues.ContainsKey(s))
  ms.RouteValues.Add(s, filterContext.RouteData.Values[s]);
  }
  }

 Your Code snippet doesnt wor well btw, it makes this:
protected override void OnActionExecuted(ActionExecutedContext filterContext) { base.OnActionExecuted(filterContext); //add sitemap routing MvcSiteMapNode ms = SiteMap.CurrentNode as MvcSiteMapNode; if (ms == null) return; if (!(filterContext.Result is ViewResult) || !ms.IsDynamic || ms.DynamicParameters == null || ms.DynamicParameters.Count == 0) return; foreach(string s in ms.DynamicParameters) { if (filterContext.RouteData.Values.ContainsKey(s) && !ms.RouteValues.ContainsKey(s)) ms.RouteValues.Add(s, filterContext.RouteData.Values[s]); } }