Question

Apparently, the title takes the value of ImageUrl

In my DynamicNodeProviderBase class configure both the Title and the ImageUrl

DynamicNodeProviderBase

const string keyFormated = "Subsidiary_{0}";

// Create a node for each subsidiary
foreach (var subsidiary in listDB.ToList())
{
    var node = new DynamicNode
                   {
                       Title = subsidiary.District,
                       Description = subsidiary.Title,
                       ImageUrl = Path.Combine(string.Format(Constants.RelativePathSubsidiary, subsidiary.ID.ToString().ToLower())),
                       Key = string.Format(keyFormated, subsidiary.District)
                   };
    node.RouteValues.Add("id", subsidiary.ID);
    node.Attributes.Add("LargeIconFileName", subsidiary.LargeIconFileName);
    node.Attributes.Add("MediumIconFileName", subsidiary.MediumIconFileName);
    node.Attributes.Add("SmallIconFileName", subsidiary.SmallIconFileName);
    returnValue.Add(node);
}

// Return 
return returnValue;

View

In my view, call the helper to generate the menu of my page. This menu is customized by a DisplayTemplates

@Html.MvcSiteMap().Menu("sitemap-menu", true, true, false)

DisplayTemplates

Basically have a DisplayTemplates for the MenuHelperModel and one for the SiteMapNodeModel. As MenuHelperModel is pretty simple (just call the helper @DisplayFor passing my custom template) will not put his code here.

The following code SiteMapNodeModel

@model SiteMapNodeModel
@{

    object upper;
    string title = Model.Title;
    var imgUrl = Path.Combine(Model.ImageUrl, "Icons");
    string iconFilename;
    if (ViewData.TryGetValue("upper", out upper))
    {
        title = title.ToUpperInvariant();
    }

    if (Model.MetaAttributes.TryGetValue("SmallIconFileName", out iconFilename)
        || Model.MetaAttributes.TryGetValue("MediumIconFileName", out iconFilename)
        || Model.MetaAttributes.TryGetValue("LargeIconFileName", out iconFilename))
    {
        imgUrl = Path.Combine(imgUrl, iconFilename);
    }
}

@if (Model.IsCurrentNode && Model.SourceMetadata["HtmlHelper"].ToString() != "MvcSiteMapProvider.Web.Html.MenuHelper")
{ 
    <text>@title</text>
}
else if (Model.IsClickable && Model.ImageUrl != null)
{ 
    <a href="@Model.Url" title="@Model.Title">
        <img src="@Url.Content(imgUrl)" alt="@Model.Title"/>
        <span>@title</span>
    </a>
}
else
{ 
    <text>@title</text>
}

But the values ​​are incorrect (or are exchanged). See a picture of the debug:

Debug

Debug mode
See full image here

NOTE: The description in red is wrong: The correct is: The Title value should be in ImageUrl property!

Question

Why the value of the ImageUrl property is Title and why TItle is empty?

Était-ce utile?

La solution

This has been fixed in version 3.2.2. It was an error during the cloning process, which incorrectly mapped the ImageUrl to Title.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top