我想在我的ASP.Net MVC 5应用程序中使用MVCSiteMapProvider。可以找到大量的资源和教程,但其中大部分都是关于基于XML的配置。使用MvcSiteMapProvider属性和属性路由
在我的应用程序属性路由已经使用,我想用属性MvcSiteMapProvider但没有足够的资源关于这种混合,我有一些问题。
例如我有像下面三个动作:
//HomeController
[Route(@"~/home", Name = "CustomerHomeIndex")]
[MvcSiteMapNode(Title = "Home Page", Key = "Home")]
public ActionResult Index() {
return View()
}
//AccountController
[Route(@"~/account", Name = "AccountIndex")]
[MvcSiteMapNode(Title = "Accounts", ParentKey = "Home", Key = "AccountIndex")]
public ActionResult Index() {
// fetching records from database
return View();
}
[Route(@"~/account-management/{id:int}/{domain:regex(^([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$)}", Name = "AccountDetail")]
[MvcSiteMapNode(Title = "Account Detail", ParentKey = "AccountIndex", Key = "AccountDetail")]
public ActionResult Details(string domain, int id) {
// fetching record from database by parameters
return View();
}
我还添加的SiteMapPath代码我的看法
//Details.cshtml
@Html.MvcSiteMap().SiteMapPath()
但没有什么是显示结果。在我看来,它是关于preservedRouteParameters
,但我找不到有关此属性路由的MvcSiteMapNode
属性中使用此参数的任何内容。
其实我还有一个关于本地化的问题,我想从资源文件中获取标题,所有东西都已经存在于全局资源文件中。我读了一些关于本地化支持的内容,但它们也与基于XML的配置有关。
感谢您的详细解答,它非常有帮助,并添加了PreservedRouteParameters解决了我的问题。而关于本地化,我不想从外部装配本地化。我已经在App_GlobalResources文件夹中有资源文件。但在MvcSiteMapNode构造函数中查找参数TitleResourceKey并看不到。如何让MvcSiteMapNode从App.GlobalResources文件中的Resources.resx文件中读取标题? – 2014-09-08 06:26:42
我试过Title =“$ resources:Resources.Resource,HomePage”但是得到了“带键的节点'Home'没有'标题'集。标题是每个节点的必填字段。错误。编辑:我将我的代码更改为Title =“$ resources:Resource,HomePage”并开始工作。谢谢你的一切 – 2014-09-08 07:28:49