Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom attributes in MvcSiteMap provider

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 <<<<<)?

like image 639
ridermansb Avatar asked Mar 10 '12 23:03

ridermansb


1 Answers

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

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

like image 123
Xharze Avatar answered Sep 27 '22 23:09

Xharze