Custom Attributes in MvcSiteMap Provider

In my Mvc.sitemap file Mvc.sitemap enter node:

 <mvcSiteMapNode title="Contato" controller="Home" action="Contato" classesCustomizadas="quebra contato" /> 

Web.config

attributesToIgnore="visibility, classesCustomizadas"

Full..

 <siteMap defaultProvider="MvcSiteMapProvider" enabled="true"> <providers> <clear /> <add name="MvcSiteMapProvider" type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider" siteMapFile="~/Mvc.Sitemap" securityTrimmingEnabled="true" cacheDuration="5" enableLocalization="true" scanAssembliesForSiteMapNodes="true" includeAssembliesForScan="" excludeAssembliesForScan="" attributesToIgnore="visibility, classesCustomizadas" nodeKeyGenerator="MvcSiteMapProvider.DefaultNodeKeyGenerator, MvcSiteMapProvider" controllerTypeResolver="MvcSiteMapProvider.DefaultControllerTypeResolver, MvcSiteMapProvider" actionMethodParameterResolver="MvcSiteMapProvider.DefaultActionMethodParameterResolver, MvcSiteMapProvider" aclModule="MvcSiteMapProvider.DefaultAclModule, MvcSiteMapProvider" siteMapNodeUrlResolver="MvcSiteMapProvider.DefaultSiteMapNodeUrlResolver, MvcSiteMapProvider" siteMapNodeVisibilityProvider="MvcSiteMapProvider.FilteredSiteMapNodeVisibilityProvider, MvcSiteMapProvider" siteMapProviderEventHandler="MvcSiteMapProvider.DefaultSiteMapProviderEventHandler, MvcSiteMapProvider" /> </providers> </siteMap> 

I edited the file "SiteMapNodeModel.cshtml" so that it can work as follows:

 @if (Model.IsCurrentNode && Model.SourceMetadata["HtmlHelper"].ToString() != "MvcSiteMapProvider.Web.Html.MenuHelper") { <text>@Model.Title</text> } else if (Model.IsClickable) { <a href="@Model.Url " class=">>>> Classes here <<<<<">@Model.Title</a> } else { <text>@Model.Title</text> } 

How to configure a class in my Mvc.sitemap file by the Mvc.sitemap attribute and replace it (→ → Classes here classesCustomizadas )?

+6
source share
1 answer

Custom attributes are stored in the MetaAttributes property on SiteMapNodeModel.

So you can get a class using: @Model.MetaAttributes["classesCustomizadas"]

+6
source

Source: https://habr.com/ru/post/910426/


All Articles