I found this question Can't use relative paths with areas in ASP.NET MVC 2 which is the same issue I am having. Is this still the case in MVC3?
Is there a way to keep content files in an area relative to the area?
So that a layout file in an area can have something like
Without having to either make a fully qualified link, requiring the areas directory and the area name or the solution of the above question which requires a check for each area on each request.
update/edit
I've decided to use both the solution in the above question and the one below (html helper) - depending on the project/situation. My implementation of the above uses app.setting to store the area names and the extensions so that I can just have the module as part of my library.
var context = HttpContext.Current;
var path = context.Request.Path;
var list = ... //code that gets from app.config and then saves it
var extensions = ... // to the cache as non-removable with a dependency on web.config
foreach (var area in list)
{
if (!path.Contains(area + "/")) continue;
foreach (var extension in extensions)
{
if (path.EndsWith("." + extension))
{
context.RewritePath(path.Replace(area + "/", "Areas/" + area + "/"));
}
}
}
See Question&Answers more detail:os