Does anyone know how to get the current folder of the view being called? I'm using AreasLib as well, so I need to get it dynamically without prefixing paths. So for example, if I do http://localhost/myarea/mycontroller/myaction
it will give me the path of Project/Areas/myarea/Views/mysubsystem
. So yeah, it needs to be the folder that the view is in.
EDIT: It's either that, or editing MvcSiteMap source code to deal with AreasLib. I'm not really equipped with the skills, or the time more importantly to deal with it.
FINAL
It's not pretty, but I had no choice whatsoever. I'm using partial views to render the menu components using the following helper to find the correct one. I'm not dealing with missing menu.ascx files in this version, but it's assumed there will always be one for now.
using System;
using System.Web;
using System.Runtime.CompilerServices;
using System.Web.Mvc;
namespace Intranet.Helpers
{
public static class StaticMenuHelper
{
public static string StaticMenu(this HtmlHelper helper, string area, string controller)
{
if (area.Equals("root"))
{
return "/Views/" + controller + "/menu.ascx";
}
else
{
return "/Areas/" + area + "/Views/" + controller + "/menu.ascx";
}
}
}
}
And the following in my Site.Master
.
<div id="menu">
<% Html.RenderPartial(Html.StaticMenu(ViewContext.RouteData.Values["area"].ToString(), ViewContext.RouteData.Values["controller"].ToString())); %>
</div>
Until MvcSiteMap has matured into something which can deal with AreasLib then I'll have to use this. I really, really don't have the time to be modifying that lib.
Thanks for all the help.