【问题标题】:MvcSiteMapProvider attribute does not workMvcSiteMapProvider 属性不起作用
【发布时间】:2017-08-02 13:49:49
【问题描述】:

我尝试将 MvcSiteMapProvider 用于面包屑。

我有以下站点地图文件:

<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
            xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd">

  <mvcSiteMapNode title="Home" controller="Home" action="Index" key="Index">
    <mvcSiteMapNode title="About" controller="Home" action="About"/>
    <mvcSiteMapNode title="Company List" controller="Company" action="Index" key="Company">
      <mvcSiteMapNode title="Create company" controller="Company" action="Create" />
    </mvcSiteMapNode>
  </mvcSiteMapNode>

</mvcSiteMap>

并显示它:

                @Html.MvcSiteMap().SiteMapPath()

它适用于“创建公司”、“公司列表”等页面

然后我想将它添加到带有参数的操作中:

        [MvcSiteMapNode(Title = "Company Details", ParentKey = "Company", Key = "CompanyDetails")]
        public ActionResult Details(int? id)
        {
...
            CompanyDetailVM model = mapper.Map<CompanyDetailVM>(company);
            return View(model);
        }

但它不起作用,根本没有显示面包屑。哪里出错了?

【问题讨论】:

    标签: asp.net-mvc breadcrumbs mvcsitemapprovider


    【解决方案1】:

    尝试将id路由参数添加到站点地图节点:

    [MvcSiteMapNode(Title = "Company Details", ParentKey = "Company", Key = "CompanyDetails", PreservedRouteParameters = "id")]
        public ActionResult Details(int? id)
        {
            ...
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-30
      • 2016-02-06
      • 2011-03-31
      • 2018-11-19
      • 2012-07-23
      • 2016-07-16
      • 2020-01-24
      • 2015-09-05
      相关资源
      最近更新 更多