Skip to content

Instantly share code, notes, and snippets.

@timgthomas
Created October 7, 2013 20:56
Show Gist options
  • Save timgthomas/05ffe58306e360905863 to your computer and use it in GitHub Desktop.
Save timgthomas/05ffe58306e360905863 to your computer and use it in GitHub Desktop.
[ChildActionOnly]
public string GetRequireJSUrl(ViewContext context)
{
var values = context.RouteData.Values;
var controller = values["controller"].ToString().ToLower();
var viewContext = (RazorView)context.View;
var viewName = Path.GetFileNameWithoutExtension(viewContext.ViewPath);
var requirePath = VirtualPathUtility.ToAbsolute("~/Content/js/lib/require-2.1.6.js");
var loc = string.Format("~/Features/{0}/{1}.js", controller, viewName);
if (System.IO.File.Exists(Server.MapPath(loc)))
{
return "<script data-main='" + VirtualPathUtility.ToAbsolute(loc) + "' src='" + requirePath + "'></script>";
}
// If we don't have a custom Require module, use the default (optional).
return "<script data-main='" + VirtualPathUtility.ToAbsolute("~/Features/Shared/Default.js") + "' src='" + requirePath + "'></script>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment