Domanda

The current node is null and breadcrumb is not rendered. Sitemap file is as following:

<mvcSiteMapNode title="Reporting" iconClass="glyphicon glyphicon-stats" key="Reporting" area="Reporting" controller="Home" action="Index">
  <mvcSiteMapNode title="ReportFolder1" iconClass="glyphicon glyphicon-stats" key="ReportingReportFolder1" route="Reporting_Report" action="Report"> <!-- acts as a folder will just redirect to reporting home -->
    <mvcSiteMapNode title="Report1" description="abc" iconClass="glyphicon glyphicon-stats" key="Report1" route="Reporting_Report" action="Report" reportPath="/Reports/Report1"></mvcSiteMapNode>
  </mvcSiteMapNode>
  <mvcSiteMapNode title="ReportFolder2" iconClass="glyphicon glyphicon-stats" key="ReportingReportFolder2" route="Reporting_Report" action="Report"> <!-- acts as a folder  will just redirect to reporting home -->
    <mvcSiteMapNode title="Report2" description="abc" iconClass="glyphicon glyphicon-stats" key="Report2" route="Reporting_Report" action="Report" reportPath="/Reports/Report2"></mvcSiteMapNode>
  </mvcSiteMapNode>
</mvcSiteMapNode>

For this, I registered a special route in the area:

context.MapRoute(
    "Reporting_Report",
    "Reporting/Report/{*reportPath}",
    new { controller = "Home", action = "Report", reportPath = UrlParameter.Optional },
    new[] { "Web.Areas.Reporting.Controllers" }
);

context.MapRoute(
    "Reporting_default",
    "Reporting/{controller}/{action}/{id}",
    new { action = "Index", id = UrlParameter.Optional },
    new[] { "Web.Areas.Reporting.Controllers" }
);

Controller action is as following:

//
// GET: /Reporting/Report/
public ActionResult Report(string reportPath)
{
    if (String.IsNullOrWhiteSpace(reportPath))
        return RedirectToAction("Index");

    if (reportPath.StartsWith("/") == false)
        reportPath = "/" + reportPath;

    var viewModel = new HomeReportViewModel();
    viewModel.ReportPath = reportPath;

    return View(viewModel);
}

The report path is successfully passed to my view model and everything works fine. The problem is that the sitemap node is not available. CurrentNode is null and the breadcrumb is not rendered.

The breadcrumb for node title "Reporting" is rendered as it should.

Any suggestions?

È stato utile?

Soluzione

I suspect this is because you are parsing "Reports/Report1" as the reportPath parameter out of your route.

context.MapRoute(
    "Reporting_Report",
    "Reporting/Report/{*reportPath}",
    new { controller = "Home", action = "Report", reportPath = UrlParameter.Optional },
    new[] { "Web.Areas.Reporting.Controllers" }
);

And in your node, you have the reportPath declared as "/Reports/Report1" (note the extra forward slash).

<mvcSiteMapNode title="Report1" description="abc" iconClass="glyphicon glyphicon-stats" key="Report1" route="Reporting_Report" action="Report" reportPath="/Reports/Report1"></mvcSiteMapNode>

For the parameter to match, the value must match exactly (except that it is a case-insensitive match).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top