Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC SiteMap

I have been going insane trying to figure out why I can't get the ASP.NET MVCSiteMap to work.

I have downloaded the latest version from CodePlex (version 2.3) and set up the references as outlined on CodePlex. I downloaded the DisplayTemplates and set up a basic Mvc.sitemap file:

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-2.0" enableLocalization="true">
    <mvcSiteMapNode title="Dashboard" controller="Admin" action="Index" changeFrequency="Always" updatePriority="Normal">
        <mvcSiteMapNode title="Users" controller="Users" action="Index" />
        <mvcSiteMapNode title="Reports" controller="Reports" action="Index" />
    </mvcSiteMapNode>
</mvcSiteMap>

When using the HTML Helper to generate a basic menu, I get a blank output:

<%: Html.MvcSiteMap().Menu() %>

In the MenuHelperModel.ascx DisplayTemplate, I am outputting the number of nodes:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl`1[ [MvcSiteMapProvider.Web.Html.Models.MenuHelperModel,MvcSiteMapProvider] ]" %>
<%@ Import Namespace="System.Web.Mvc.Html" %>
<%@ Import Namespace="MvcSiteMapProvider.Web.Html.Models" %>

<%: Model.Nodes.Count %>

<ul>
<% foreach (var node in Model.Nodes) { %>
    <li><%=Html.DisplayFor(m => node)%>
    <% if (node.Children.Any()) { %>
        <%=Html.DisplayFor(m => node.Children)%>
    <% } %>
    </li>
<% } %>
</ul>

The resulting output is:

0

I cannot figure out what I am doing wrong. I don't get any errors, and I am using the Mvc.sitemap file provided by the CodePlex project site with some minor modifications for my actions/controllers.

NOTE: I have also downloaded the sample project, but it will not compile for me and the sitemap file being used is way too complicated for me to figure out at this early stage in my understanding of how to use this.

Any help is greatly appreciated.

like image 963
dotariel Avatar asked Nov 15 '22 04:11

dotariel


1 Answers

The 2.3 version is ready for MVC3. I recompiled the fresh source, had the add a reference to MVC2 assemblies, change two code lines until I had a working MvcSitemap.dll

In your Mvc.sitemap I had to change the namespace to:

http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0

(note the -3.0 at the end instead of -2.0, in the latest version it is -4.0 at the end)

And make sure the name of the controller matches a controller where you test it otherwise the security mechanism will prevent anything showing.

Please note that the project has moved to Github the namespace is still referencing codeplex.com.

like image 50
rene Avatar answered Mar 11 '23 15:03

rene