[英]ASP.NET MVC store CSS class in the node
I would like to add icons from Font Awesome to my sitemap. 我想将Font Awesome中的图标添加到我的站点地图中。 I want to store related classes in my node and then, in my
menuHelperMode.cshtml
assign this class to related place holder: 我想在我的节点中存储相关的类,然后在我的
menuHelperMode.cshtml
分配给相关的占位符:
<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. 从目前为止我所看到的,我认为它可以工作,但是我找不到方法如何访问
.cshtml
文件中的此自定义节点。 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? 所以我的问题是,如何直接从
cshtml
Razor布局访问我的自定义节点属性?
Attributes of the node can be accessed via Attributes property: 可以通过Attributes属性访问节点的属性:
if (child.Attributes.ContainsKey("iconClass"))
{
<div class="@("circle " + child.Attributes["iconClass"])">
}
else
{
<div class="circle">
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.