2017-08-02 193 views
0

我嘗試使用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() 

它工作正常網頁 「創建公司」, 「公司名單」 等

然後我想添加它用於參數的動作:

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

但它不起作用,根本不顯示麪包屑。哪裏出錯?

回答

0

嘗試id路由參數添加到站點地圖結點:

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