ASP.NET MVC store CSS class in the node

418 views Asked by At

I would like to add icons from Font Awesome to my sitemap. I want to store related classes in my node and then, in my menuHelperMode.cshtml assign this class to related place holder:

<mvcSiteMapNode title="Documents" controller="Documents" action="Index" iconClass ="fa fa-file-text"/>

From what i have seen so far, i assume it can work, however i can't find a method how can i access this custom node in my .cshtml file. I have tried this (as mentioned in related question):

<div class="@("circle " + child["iconClass"])">

But it can not be indexed like [""] here. I think, it works for binding events only. So my question is, how can i access my custom node attribute directly from cshtml Razor layout?

1

There are 1 answers

0
Andrei On BEST ANSWER

Attributes of the node can be accessed via Attributes property:

if (child.Attributes.ContainsKey("iconClass"))
{
    <div class="@("circle " + child.Attributes["iconClass"])">
}
else
{
    <div class="circle">
}