mvc.sitemap 中的 2 个节点指的是具有不同参数的 1 个动作,它们未显示在面包屑中

2 nodes in mvc.sitemap refers to 1 action with different parameters and they are not shown in breadcrumbs

我有一个 link "Ticket/Index" 具有不同的参数。我用这个 link 创建了一个菜单,它的参数使用路由。菜单显示正确,但面包屑不显示!

Mvc.sitemap:

<mvcSiteMapNode id="Admin" title="Admin Menu"  clickable="false" imageUrl="fa fa-th" >
    <mvcSiteMapNode title="Users"  controller="User" action="Index" />
    <mvcSiteMapNode title="Projetcs"  controller="Project" action="Index" />
    <mvcSiteMapNode title="Admin Tickets" controller="Admin" action="Index" /> ===> Ticket/index?role=0
</mvcSiteMapNode>

<mvcSiteMapNode id="Supporter" title="Support Menu"    clickable="false" imageUrl="fa fa-th" >
    <mvcSiteMapNode title="New Tickets" controller="Support" action="ListWaiting" /> ===> Ticket/Index?role=3&mode=receive&status=0
    <mvcSiteMapNode title="Add New Ticket"  controller="Ticket" action="Insert"/> 
</mvcSiteMapNode>

RouteConfig.cs :

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "AdminTicketIndex",
            url: "Admin/Index",
            defaults: new { controller = "Ticket", action = "Index", role = 0 });

        routes.MapRoute(
            name: "SupportTicketIndex",
            url: "Support/ListWaiting",
            defaults: new { controller = "Ticket", action = "Index", role = 3, mode = "receive", status = 0 });

        routes.MapRoute(
          name: "Default",
          url: "{controller}/{action}/{id}",
          defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional });
    }

哇!我找到了!我将 url 添加到节点元素,并为此使用了以下路由。现在我可以看到每个菜单的面包屑。线索是将 url 添加到 SiteMapNode。

mvc.sitemap:

  <mvcSiteMapNode id="Admin" title="Admin Menu" clickable="false" imageUrl="fa fa-th" >
      <mvcSiteMapNode title="Users" controller="User" action="Index" />
      <mvcSiteMapNode title="Projetcs" controller="Project" action="Index" />
      <mvcSiteMapNode title="Admin Tickets" controller="Ticket" action="Index/0" url="/Ticket/Index/0" />
    </mvcSiteMapNode>

   <mvcSiteMapNode id="Supporter" title="Support Menu" clickable="false" imageUrl="fa fa-th" >
      <mvcSiteMapNode id="Waiting" title="New Tickets" controller="Ticket" action="Index/3/receive/0" url="/Ticket/Index/3/receive/0" />
        <mvcSiteMapNode title="Add New Ticket" controller="Ticket" action="Insert/3" url="/Ticket/Insert/3"/>
   </mvcSiteMapNode>

RouteConfig.cs :

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
          name: "TicketIndex",
          url: "{controller}/{action}/{role}/{mode}/{status}",
          defaults: new { controller = "Ticket", action = "Index", role = UrlParameter.Optional, mode = UrlParameter.Optional, status = UrlParameter.Optional });

        routes.MapRoute(
          name: "Default",
          url: "{controller}/{action}/{id}",
          defaults: new {controller = "Account", action = "Login", id = UrlParameter.Optional });

    }