Custom attributes in MvcSiteMap provider
Asked Answered
D

1

6

In my file Mvc.sitemap, have the following 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 he could 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 get the class configured in my file Mvc.sitemap on attribute classesCustomizadas and replace (>>>> Classes here <<<<<)?

Dioptase answered 10/3, 2012 at 23:40 Comment(1)
The value you have used for attributesToIgnore didn't work for me. The comma-separated list of attributes can't contain any whitespace around the commas. I'm using version 3.1.Antiquary
M
6

The custom attributes are stored in the property MetaAttributes on SiteMapNodeModel.

Therefore you can get the class using: @Model.MetaAttributes["classesCustomizadas"]

Mandel answered 12/4, 2012 at 10:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.