2013-03-21 73 views
0

我使用MVC站點地​​圖提供用於創建一些麪包屑MvcSiteMapProvider與Razor視圖側獲取當前節點的父母

我想做的事;用剃刀

創建視圖上的麪包屑我想做些像調用下面顯示

<div id="navbar"> 
    <div>YOU ARE HERE: 
     // There is no calls like this but you get the idea 
     @if (SiteMap.CurrentNode.HasParentNodes == true) 
     { 
      // I'd like to loop trough each parent till the RootNode 
      foreach (SiteMapNode Snode in SiteMap.CurrentNode.ParentNodes) 
      { 
       <a href="@Snode.Url">@Snode >></a> 
      } 
     } else { 
      // If there is no parent just show current node 
      <a href="@SiteMap.CurrentNode.Url.ToString()">@SiteMap.CurrentNode</a> 
     } 
    </div> 
    <div>@DateTime.Now.Date.ToLongDateString()</div> 
</div> 

所以,我怎麼能實現在此查看使用剃刀?

回答

1

@Html.MvcSiteMap().SiteMapPath() HTML助手已經這樣做了。這是一個模板化控件,您可以通過編輯/Views/Shared/DisplayTemplates/SiteMapPathHelperModel.cshtml文件進行修改,所以基本上可以獲得任何您想要的HTML輸出。

如果你仍然喜歡這樣做後知道,你也可以用MvcSiteMapProvider.SiteMaps.Current.CurrentNode.Ancestors財產(版本4及以上)做到這一點。