I would like to auto-generate some JavaScript files with the corresponding .js extensions in my URLs using ASP.NET MVC 5.
Here is my problem;
I use require.js on my website and it works very well. However, not all of my JavaScript files are real files on disk. Some of them must be created at runtime. Therefore, I wrote a controller that generates dynamic JavaScript files and serves them when using default routing;
// ~/Resource/CommonRes -- from ResourceController.CommonRes() define([], function() { return { "menuItemConfiguration":"Configuration", "menuItemAdmin":"Admin", "manageAccount":"Manage Account", "logOff":"Log off" ... }; });
However, I need the route to be accessible as ~/Scripts/Resources/CommonRes.js - the .js extension is vital since I actually return require.js , which will be called like this:
require(['Resources/CommonRes'], function(commonRes) {
And in this case, a module named Resources/CommonRes will always look in ~/Scripts/Resources/CommonRes.js . Therefore, you must service it with this extension.
I cannot configure routing correctly. I tried the following, but to no avail;
routes.MapRoute( name: "Resource Scripts", url: "Scripts/Resource/{action}", defaults: new { controller = "Resource" }, namespaces: new string[] { "AITrackRecord.Controllers" } );
source share