我是 MvcSiteMapProvider 的新手。不幸的是无法自己找到答案。我使用 MVC4 和 MvcSiteMapProvider 我的问题:
1)链接购买(和购买->搜索)将我链接到本地主机,但它必须是本地主机/购买/搜索
2) Toy/Toy-Details/1 链接不属于“购买”菜单(如果我到达此链接菜单购买->搜索消失)提前谢谢你。
我的 Mvc.sitemap:
<mvcSiteMapNode title="Home"
controller="Toy"
action="Index"
key="Home">
<mvcSiteMapNode title="Buy"
controller="Toy"
action="Search"
key="ToyBuy">
<mvcSiteMapNode title="Search"
controller="Toy"
action="Search"
key="ToySearch">
<mvcSiteMapNode title="Toy Search Result"
controller="Toy" action="Search-Result"
key="ToySearchResult">
<mvcSiteMapNode title="Toy Details"
controller="Toy"
action="Toy-Details"
key="ToyDetail" dynamicNodeProvider="MyToys.Web.DynamicNodeProviders.ToySearchDynamicNodeProvider,MyToys.Web"/>
</mvcSiteMapNode>
</mvcSiteMapNode>
<mvcSiteMapNode title="Publish" controller="Toy" action="Publish" description=""/>
<mvcSiteMapNode title="Published" controller="Toy" action="Published" key="ToyPublished" description="">
<mvcSiteMapNode title="Edit" controller="Toy" action="Edit"
preservedRouteParameters="id" key="ToyPublishedEdit" visibility="false" description=""/>
</mvcSiteMapNode>
和 ToySearchDynamicNodeProvider:
public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
{
var rep = new ToyRepository();
foreach (var Toy in rep.Get())
{
DynamicNode dynamicNode = new DynamicNode();
dynamicNode.ParentKey = "ToySearchResult";
dynamicNode.RouteValues.Add("id", Toy.ID);
yield return dynamicNode;
}
}
顺便说一句,我还重写了 MenuHelperModel.cshtml:
<div class="hmenu">
<ul class="tabs">
@foreach (var node in Model.Nodes)
{
<li>@Html.DisplayFor(m => node)</li>
}
</ul>
</div>
@foreach (var node in Model.Nodes)
{
if (node.IsInCurrentPath)
{
if (node.Children.Any())
{
<div class="vmenu">
<ul class="tabs">
@foreach (var child in node.Children)
{
<li><a href="@child.Url">@child.Description</a></li>
}
</ul>
</div>
}
}
}