I am working on an ASP.net MVC application. One thing that I really like about ASP.net MVC is the way it allows you to reference relative paths in server code. I was wondering if there is a standard way to do this in client code.
I have a way to do this. I am writing the following on my layout page.
<script type="text/javascript"> var ApplicationPath = '@Url.Content("~/")'; </script>
By making this the first script on my layout page, I can reference relative paths from any .js file using the ApplicationPath variable. This seems to work well, but I can only wonder if there is a built-in way to work with relative paths in JavaScript. This works well for me, but someone else may use a different convention.
Does ASP.net MVC 4 have a standardized way to access relative paths in JavaScript?
source share