2012-08-01 71 views
1

我有一个ASP MVC网站地图,看起来像这样ASP MVC站点地​​图有一个图像HTML助手?

<mvcSiteMapNode title="Home" imageUrl="home.png" controller="Home" action="Index"> 
     <mvcSiteMapNode title="Search" controller="Search" imageUrl="magnifying_glass.png" action="Index"> 

节点都有一个“IMAGEURL”属性分配给他们,我想我的看法中访问。我知道有包含这让我的标题获得图书馆内的地图帮手通过

@Html.MvcSiteMap().SiteMapTitle() 

不过,我看不到获得imgUrl的任何方式。在写我自己的之前,有没有人知道这是否已经存在?我已经搜索过,但无法在现有库中找到任何方法。

回答

2

好的,我刚刚写了一些东西。这很简单。

public static class MvcSiteMapImageUrlHelper 
    { 
     public static MvcHtmlString SiteMapImageUrl(this MvcSiteMapHtmlHelper helper) 
     { 
      var node = helper.Provider.CurrentNode; 

      if (node != null) 
      { 
       return new MvcHtmlString(node["ImageUrl"]); 
      } 

      return new MvcHtmlString(string.Empty); 
     } 
    }