I setup MVC breadcumbs for my website using MvcSiteMapProvider (Nuget package MvcSiteMapProvider.MVC5 (version 4.6.22)).
It works fine.
Then I want to update Url of Sitemap dynamically like:
SiteMaps.Current.CurrentNode.Url = Url.Action("Index");
Then I got this error:
SiteMapNode is readonly, property 'Url' cannot be modified
Note that I am still able to update Title:
SiteMaps.Current.CurrentNode.Title = "/Index";
Any idea?
The
SiteMapis a statically cached object that is shared between all users. Technically, all of the properties are read-only at runtime. However, some of the properties (such asTitle) are request-cached so you can safely update them at runtime without affecting other users.The
Urlproperty is a special property that dynamically builds the URL through the MVCUrlHelperclass (which is directly driven from your routes). It makes no sense to set it toUrl.Action("Index")because that is effectively what it does just by itself (unless you are using a dynamic node provider or customISiteMapNodeProvider- those are startup extension points where you load the node configuration, so the properties are read-write).You just need to set the correct controller and action in your node configuration (which could be XML, attribute based, or code based) and the URL will resolve on its own.
XML Example