I am trying to accomodate a corporate standard where all page-level javascript is contained in an external file and not included within the ASPX or ASCX file. Using ASP.NET MVC 2, I'm wondering how I can reference the script file (.js) relative to the view.
In other words, I don't want to polute my Scripts folder with all of the small .js files that will exist in the application. From an organizational perspective, having the .js file alongside the .aspx/.ascx file makes the most sense. For example, if I have a controller named "MyController" with an action named "MyAction", I would have a MyAction.aspx file in the Views/MyController folder and would like to place the script file named "MyAction.js" in the same folder. However, I can't use:
<script src="MyAction.js" type="text/javascript"></script>
and it appears that this doesn't work either:
<script src="<%= Url.Content("~/Views/MyController/MyAction.js") %>"
type="text/javascript"></script>
So I'm guessing the problem may have to do with the routing table, but I'm still a MVC newbie, so I'm not sure.
Second question, is it possible to embed the javascript as a resource like we can with traditional ASP.NET and generate the non-human-readable url in our client page?
UPDATE
I can only assume that this question has become stale which is why no one else has offered any answers. I can't believe it's that difficult of a question. So, I thought I'd add this little update to see if I can resuscitate the conversation.