3

我有一個簡單的網站地圖:MVCSiteMapProvider不顯示的SiteMapPath

<mvcSiteMapNode title="Projects" controller="Projects" action="Index"> <!--This wraps the entire site since Projects Index is the homepage--> 
    <mvcSiteMapNode title="Projects" controller="Projects" action="Index"> 
     <mvcSiteMapNode title="Project" controller="Projects" action="Details"> 
     <mvcSiteMapNode title="Session" controller="Session" action="DetailsNew" /> 
     <mvcSiteMapNode title="Edit Session" controller="Session" action="Edit" /> 
     </mvcSiteMapNode> 
    </mvcSiteMapNode> 
    <mvcSiteMapNode title="My Account" controller="Account" action="ChangePassword" /> 
    <mvcSiteMapNode title="Admin" controller="Admin" action="Index" > 
     <mvcSiteMapNode title="Create User" controller="Admin" action="AddUser" /> 
     <mvcSiteMapNode title="Manage Users" controller="Admin" action="Users" /> 
    </mvcSiteMapNode> 
    </mvcSiteMapNode> 

當我把我的@Html.MvcSiteMap().SiteMapPath()項目詳情頁面,沒有顯示上。想法?

回答

3

當您添加自定義路由值(「area」,「controller」或「action」以外的其他值)時,您需要明確指定如何匹配它。

默認情況下,您需要爲每個潛在路由鍵值創建一個節點。例如,如果您有一個名爲「id」的路由鍵,並且具有ID爲「1」,「2」和「3」的記錄,則需要爲每個ID創建一個節點。

<mvcSiteMapNode title="Project 1" controller="Project" action="Details" id="1"> 
<mvcSiteMapNode title="Project 2" controller="Project" action="Details" id="2"> 
<mvcSiteMapNode title="Project 3" controller="Project" action="Details" id="3"> 

你已經發現了替代,這是使用preservedRouteParameters。這將使節點始終匹配路由密鑰,而不管其值如何,這通常是執行CRUD操作的管理頁面的理想解決方案。

<mvcSiteMapNode title="Edit Project" controller="Project" action="Edit" preservedRouteParameters="id"> 

通常當你這樣做,你必須修復了顯示一點,因爲它並沒有多大意義,菜單上有一個編輯節點(您通常會挑選出編輯記錄列表),當您選擇它時,您通常希望節點顯示您選擇的記錄。你可以使用FilteredSiteMapNodeVisibilityProviderSiteMapTitleAttribute來做到這一點。

有關如何設置一組CRUD操作的完整下載演示,請參閱標題爲How to Make MvcSiteMapProvider Remember a User's Position的博客文章。