Last active
August 29, 2015 14:13
-
-
Save philipooo/2aea22f1ff64182e7a7b to your computer and use it in GitHub Desktop.
Resolver for RequireJsNet to find Javascript nested in areas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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