2

We have an MVC3 application in IIS7: http://mydomain.com/myapplication/

What would be the relative URL in javascript for:

http://mydomain.com/myapplication/mycontroller/myaction

/mycontroller/myaction - goes to http://mydomain.com/mycontroller/myaction

../mycontroller/myaction - goes up one level (in this case also to http://mydomain.com/mycontroller/myaction)

mycontroller/myaction - goes to http://mydomain.com/myapplication/mycontroller/myaction when running as dev on localhost but on server goes to http://mydomain.com/mycontroller/myaction

./mycontroller/myaction - was what I figured would be right, but that didn't work either!

3
  • Just omit the / altogether and it would look in the same level as the original page having the code. Commented Nov 16, 2011 at 15:01
  • Sorry, re-read my Q and it was not really correct, hence the answers... Commented Nov 16, 2011 at 15:10
  • So what you're after is to get the application root? If so, jmav's answer looks correct. Commented Nov 16, 2011 at 15:47

2 Answers 2

2

If you are developing in ASP.NET MVC you can set root var on server side like this:

<script language="javascript" type="text/javascript">
   var root = '<%= this.Request.ApplicationPath%>';
</script>

and use it in JS:

<script language="javascript" type="text/javascript">    
   img = root + '/someotherrootfile.js'
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

You would just list the file name.

<script src="filename.js"></script>

If I understand you correctly you would only need to list the filename or path directory with no leading slash.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.