Skip to content

Instantly share code, notes, and snippets.

@philipooo
Last active August 29, 2015 14:13
Show Gist options
  • Save philipooo/2aea22f1ff64182e7a7b to your computer and use it in GitHub Desktop.
Save philipooo/2aea22f1ff64182e7a7b to your computer and use it in GitHub Desktop.
Resolver for RequireJsNet to find Javascript nested in areas
public class AreaEntryPointResolver : IEntryPointResolver
{
public string Resolve(ViewContext viewContext, string entryPointRoot)
{
if (viewContext.RouteData.DataTokens["area"] == null)
return null;
var area = viewContext.RouteData.DataTokens["area"].ToString();
var controller = viewContext.Controller.ValueProvider.GetValue("controller").RawValue as string;
var action = viewContext.Controller.ValueProvider.GetValue("action").RawValue as string;
var server = viewContext.HttpContext.Server;
// search for scripts/controller/action.js in current area
var entryPoint = "~/Areas/" + area + "/Scripts/" + controller + "/" + action + ".js";
var filePath = server.MapPath(entryPoint);
return File.Exists(filePath) ? UrlHelper.GenerateContentUrl(entryPoint, viewContext.HttpContext) : null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment