Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why use @Url.Content

Tags:

Can someone please explain why I should use (or should I?):

<script type="text/javascript" src="@Url.Content("/Scripts/SomeScript.js")"></script>

vs

 <script type="text/javascript" src="/Scripts/SomeScript.js"></script>

Thanks

like image 880
raklos Avatar asked Mar 01 '12 11:03

raklos


1 Answers

The fragment @Url.Content("/Scripts/SomeScript.js") does absolutely nothing, and is equivalent to just /Scripts/SomeScript.js.

However, for paths starting with "~", it will translate the url to the correct, application relative url, e.g., @Url.Content("~/Scripts/SomeScript.js") could translate to /MyVirtualDirectory/Scripts/SomeScript.js, if you deployed your web application to a virtual directory MyVirtualDirectory below the root folder of the web site.

like image 169
Ruben Avatar answered Dec 23 '22 17:12

Ruben