MVC Sitemap Provider - DynamicNodeProvider 导致面包屑消失
我正在尝试使用 http://mvcsitemap.codeplex.com/ 中的 MvcSiteMapProvider 为我的网站。我有一些页面需要在 URL 中传递 ID,因此我尝试使用动态节点来完成此操作。但是,对于我声明为动态的所有节点,相应页面上不会出现面包屑。当我在 DynamicNodeProvider 类中使用断点进行调试时,我也遇到了一个有趣的错误。下面是该类的基本版本和站点地图节点:
public class UserSummaryDynamicNodeProvider : DynamicNodeProviderBase
{
private static ServiceClient proxy = new ServiceClient();
List<User> users = proxy.GetUsers();
public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
{
var nodes = new List<DynamicNode>();
foreach (var user in users)
{
DynamicNode node = new DynamicNode();
node.Key = "UserSummary";
node.ParentKey = "UserMenu";
node.RouteValues.Add("userID", user.ID);
nodes.Add(node);
}
return nodes;
}
}
<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalizatoin="true">
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="User Menu" controller="UserInfo" action="UserMenu">
<mvcSiteMapNode title="User Summary" controller="UserInfo" action="UserSummary" dynamicNodeProvider="MySite.Users.DynamicNodeProviders.UserSummaryDynamicNodeProvider, MySite.Users" />
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMap>
我收到的错误是“没有可用的源”,并且似乎是在我未指定的位置 (c :\Projects\Codeplex\TFS10\mvcsitemap\Branches\3.1.0\src\MvcSiteMapProvider\MvcSiteMapProvider)。我从 codeplex 站点下载了 dll,并且此类包含在库中,但源文件未单独包含在下载中。我已经包含了适当的程序集引用(MvcSiteMapProvider 和 MvcSiteMapProvider.Extensibility)。我在这里遗漏了一些明显的东西吗?
这可能不是我这里唯一的问题。在尝试使用动态节点之前,我尝试将 [SiteMapPreserveRouteData] 属性添加到我的操作结果中,但这也不起作用。在这种情况下,面包屑仍然会出现,但路由中的任何 ID 参数都不会保留。有什么想法为什么行不通吗?只是为了澄清一下,我正在使用 MVC3 和 .NET 4.0
如果我需要提供更多信息,请告诉我。
I am trying to use MvcSiteMapProvider from http://mvcsitemap.codeplex.com/ to generate a breadcrumb trail for my website. I have some pages that require an ID to be passed in the URL, so I'm trying to use dynamic nodes to accomplish this. However, for all the nodes that I declare as dynamic, no breadcrumbs appear on the respective page. I am also getting an interesting error when I debug with a breakpoint in my DynamicNodeProvider class. Here is a basic version of the class, and the sitemap node:
public class UserSummaryDynamicNodeProvider : DynamicNodeProviderBase
{
private static ServiceClient proxy = new ServiceClient();
List<User> users = proxy.GetUsers();
public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
{
var nodes = new List<DynamicNode>();
foreach (var user in users)
{
DynamicNode node = new DynamicNode();
node.Key = "UserSummary";
node.ParentKey = "UserMenu";
node.RouteValues.Add("userID", user.ID);
nodes.Add(node);
}
return nodes;
}
}
<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalizatoin="true">
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="User Menu" controller="UserInfo" action="UserMenu">
<mvcSiteMapNode title="User Summary" controller="UserInfo" action="UserSummary" dynamicNodeProvider="MySite.Users.DynamicNodeProviders.UserSummaryDynamicNodeProvider, MySite.Users" />
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMap>
The error I get says "No Source Available" and appears to be looking for a specific C# source file (MvcSiteMapNode.cs) in a location I haven't specified (c:\Projects\Codeplex\TFS10\mvcsitemap\Branches\3.1.0\src\MvcSiteMapProvider\MvcSiteMapProvider). I downloaded the dll from the codeplex site, and this class is included in the library, but the source files aren't included individually in the download. I've included the appropriate assembly references (both MvcSiteMapProvider and MvcSiteMapProvider.Extensibility). Am I missing something obvious here?
This might not be my only problem here. Before I tried using dynamic nodes, I tried adding the [SiteMapPreserveRouteData] attribute to my action results, but that didn't work either. In that case the breadcrumb still appears, but none of the ID parameters in the route are preserved. Any ideas why that wouldn't work? Just to clarify, I'm using MVC3 and .NET 4.0
Please let me know if I need to provide some more info.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 CodePlex 上提到的:尝试最新的 3.1.0 分支应该可以解决这个问题。
As mentioned on CodePlex: try the latest 3.1.0 branch which should fix this.