문제

I have an ASP MVC Sitemap which look something like this

<mvcSiteMapNode title="Home" imageUrl="home.png" controller="Home" action="Index">
        <mvcSiteMapNode title="Search" controller="Search" imageUrl="magnifying_glass.png" action="Index">

The nodes all have an 'imageUrl' property assigned to them which I would like to access within my view. I know there is a SiteMap helper included within the library which allows me to the get the title via

@Html.MvcSiteMap().SiteMapTitle()

However, I can't see any way of obtaining the imgUrl. Before I write my own, does anybody know if this already exists? I've search around but can't find any way of doing it within the existing library.

도움이 되었습니까?

해결책

OK, I've just written something myself. It's very simple.

public static class MvcSiteMapImageUrlHelper
    {
        public static MvcHtmlString SiteMapImageUrl(this MvcSiteMapHtmlHelper helper)
        {
            var node = helper.Provider.CurrentNode;

            if (node != null)
            {
                return new MvcHtmlString(node["ImageUrl"]);
            }

            return new MvcHtmlString(string.Empty);
        }
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top