当前节点为null,并且不呈现痕迹导览。 Sitemap文件如下:
<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>
为此,我在该地区注册了一条特殊路线:
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" }
);
控制器操作如下:
//
// 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);
}
报告路径已成功传递到我的视图模型,一切正常。问题是站点地图节点不可用。 CurrentNode为null,并且不呈现面包屑。
节点标题的面包屑&#34;报告&#34;按原样呈现。
有什么建议吗?
答案 0 :(得分:0)
我怀疑这是因为你正在解析&#34; Reports / Report1&#34;作为路径中的reportPath参数。
context.MapRoute(
"Reporting_Report",
"Reporting/Report/{*reportPath}",
new { controller = "Home", action = "Report", reportPath = UrlParameter.Optional },
new[] { "Web.Areas.Reporting.Controllers" }
);
在您的节点中,您将reportPath声明为&#34; / Reports / Report1&#34; (注意额外的正斜杠)。
<mvcSiteMapNode title="Report1" description="abc" iconClass="glyphicon glyphicon-stats" key="Report1" route="Reporting_Report" action="Report" reportPath="/Reports/Report1"></mvcSiteMapNode>
要匹配的参数,该值必须完全匹配(除了它是不区分大小写的匹配)。