Let’s say I have a file located at C:\foo\bar.js and I want to include this file in an ASP.NET MVC website that is, obviously, hosted on the same machine.
This doesn’t work:
<script src="C:\foo\bar.js"></script>
And neither does this:
<script src="file:///C:/foo/bar.js"></script>
The above two lines do not make sense either since they would look at the client’s folder, not the server’s folder.
So how can I serve this file from an ASP.NET MVC Controller (in the controller, I have the string value of the path of the local physical file i.e. C:\foo\bar.js) to a View? Maybe something with an HttpHandler?
Note: This solution is assuming that the js file is not part of the web app. If it is, you should probably be using Url.Content or ResolveClientUrl instead..
You should be able to link to a controller action Url in your script tag:
…and have an action like::
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.file(VS.90).aspx