0

global.asax に 2 つのルートがあります

        routes.MapRoute(
            "DefaultFriendlyUrl",
            "Page/{FriendlyUrl}",
            null,
            new string[] { "MvcApplication2.Controllers" }
        ).RouteHandler = new FriendlyUrlRouteHandler();


        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "index", id = UrlParameter.Optional },
            new string[] { "MvcApplication2.Controllers" }
        );

したがって、FriendlyUrlRouteHandler はすべての /Page/blablabla ルートを機能させ、1 つのアクション Index で PageController に送信します

public class FriendlyUrlRouteHandler : MvcRouteHandler
{
    protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        var friendlyUrl = (string)requestContext.RouteData.Values["FriendlyUrl"];

        PageItem page = null;

        if (!string.IsNullOrEmpty(friendlyUrl))
            page = PageManager.GetPageByFriendlyUrl(friendlyUrl);

        if (page == null)
        {
            requestContext.RouteData.Values["controller"] = "home";
            requestContext.RouteData.Values["action"] = "index";
            requestContext.RouteData.Values["id"] = null;
        }
        else
        {
            requestContext.RouteData.Values["controller"] = "page";
            requestContext.RouteData.Values["action"] = "index";
            requestContext.RouteData.Values["id"] = page.PageID;
        }

        return base.GetHttpHandler(requestContext);
    }
}

次に、PageController が自分のページのコンテンツを取得して表示します。しかし、MvcSiteMapProvider はこれらのページのブレッドクラムを表示しません

SiteMap.cs

public class SiteMap : DynamicNodeProviderBase
{
    public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
    {
        var returnValue = new List<DynamicNode>();
        returnValue.Add(new DynamicNode() { Key = "id1", Title="CustomPage", Controller="Page", Action="Index" });
        return returnValue;
    }
}

私の CustomPage は @Html.MvcSiteMap().SiteMapPath() に存在しませんが、ページは正しく表示されます。私のコードで何が間違っていますか? そのため、ブレッドクラム文字列でカスタム ページのツリーを構築することはできません...

4

1 に答える 1

1

Mvc.sitemap を提供してください。

DynamicNode のインスタンスに ParentKey がないようです。

于 2011-09-23T13:31:52.400 に答える