model-view-controller - MVCSiteMapProvider 不显示 SiteMapPath

标签 model-view-controller asp.net-mvc-5 sitemap mvcsitemapprovider

我有一个简单的站点地图:

<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() 放在我的项目详细信息页面上时,没有任何显示。想法?

最佳答案

当你添加一个自定义路由值(“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">

通常当您这样做时,您必须稍微修正显示,因为在菜单上有一个编辑节点没有多大意义(您通常会从记录列表中选择编辑)并且当您选择它您通常希望节点显示您选择的记录。您可以使用 FilteredSiteMapNodeVisibilityProvider 执行此操作和 SiteMapTitleAttribute .

有关通常如何设置一组 CRUD 操作的完整可下载演示,请参阅标题为 How to Make MvcSiteMapProvider Remember a User's Position 的博客文章.

关于model-view-controller - MVCSiteMapProvider 不显示 SiteMapPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21913779/

相关文章:

css - 如何更改 MVC 5 @Html.EditorFor 宽度

c# - MVC5 Identity UserManager.Update(用户)不工作

用于从 Magento 中的 sitemap.xml 中排除特定类别页面的 PHP 代码

php - 如何在 laravel 中创建 sitemap.xml.gz

ruby-on-rails - 验证网址 |前置 http ://

node.js - 如何避免 node.js + mongoose 应用程序中的胖模型?

c# - View 序列化时链接中断

ruby-on-rails - 网站搜索引擎优化是否受益于在使用微数据之上拥有站点地图?

java - 将自定义对象从 thymeleaf View 传递到 Controller

php - 我应该在 HMVC Codeigniter 中将其设为不同的模块吗?