MvcSiteMapProvider属性不起作用

时间:2017-08-02 13:49:50

标签: asp.net-mvc breadcrumbs mvcsitemapprovider

我尝试将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()

它适用于页面&#34;创建公司&#34;,&#34;公司列表&#34;等

然后我想用参数添加它来执行操作:

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

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

1 个答案:

答案 0 :(得分:0)

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

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