【发布时间】:2014-03-14 14:30:39
【问题描述】:
当前节点为空,不渲染面包屑。站点地图文件如下:
<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,并且未呈现面包屑。
节点标题“Reporting”的面包屑按原样呈现。
有什么建议吗?
【问题讨论】:
标签: c# asp.net-mvc mvcsitemapprovider