This is more of an MVC issue than MvcSiteMapProvider, as MvcSiteMapProvider is using the default templated HTML helper behavior.
It took some searching, but I found a way to override this behavior by adding additional paths to the default MVC view search locations:
Can I Add to the Display/EditorTemplates Search Paths in ASP.NET MVC 3?
System.Web.Mvc.RazorViewEngine rve = (RazorViewEngine)ViewEngines.Engines
.Where(e=>e.GetType()==typeof(RazorViewEngine))
.FirstOrDefault();
string[] additionalPartialViewLocations = new[] {
"~/Views/GeneralTemplates/{0}.cshtml"
};
if(rve!=null)
{
rve.PartialViewLocationFormats = rve.PartialViewLocationFormats
.Union( additionalPartialViewLocations )
.ToArray();
}
I don't believe it is possible to remove the /DisplayTemplates
folder from the path, as that is a convention (to keep it separate from /EditorTemplates
). So, the best you will be able to do is make a folder ~/Views/GeneralTemplates/DisplayTemplates/
using the configuration above.
Note that MVC checks for a /DisplayTemplates
folder in the same directory as your view first before going to /Views/Shared/DisplayTemplates
, so you could also move them to the same view(s) directory where their corresponding HTML helpers are used.
I haven't tried, but it may also be possible to use a complete view path (i.e. ~/Views/GeneralTemplates/SiteMapPathHelperModel.cshtml
) when specifying the template.
@Html.MvcSiteMap().SiteMapPath("~/Views/GeneralTemplates/SiteMapPathHelperModel.cshtml")
Important: If you change the location of all of the templates like this, you will probably need to go through the recursive templates and change all of DisplayFor
locations within them as well.
@model MvcSiteMapProvider.Web.Html.Models.SiteMapPathHelperModel
@using System.Web.Mvc.Html
@using System.Linq
@using MvcSiteMapProvider.Web.Html.Models
@foreach (var node in Model) {
@Html.DisplayFor(m => node); @* // <-- Need to add the diplaytemplate here, too *@
if (node != Model.Last()) {
<text> > </text>
}
}
You could instead build custom HTML helpers that are non-templated to work around this issue if the other solutions don't work for you.