문제

I recently upgraded a MVC 3 project to MVC 4.

In the app there are 3 areas. The areas use the same scripts as elsewhere.

Before the upgrade views in areas just used scripts from the Main Scripts folder ( /Scripts) but now I get a 404 (Not Found) because its looking here - /AREANAME/Scripts/jquery-1.10.1.min.js

Obviously I dont want to duplicate the scripts folder to all the areas folders so my question is how do I make the areas use the scripts in the main folder?

I reference the scripts like this in layout page

도움이 되었습니까?

해결책

Don't use relative addressing. Instead, use the MVC supplied tools for this:

<script src="@Url.Content("~/Scripts/jquery-1.10.1.min.js")"></script>

Even better, use the bundling and minification supplied tools in MVC4.

다른 팁

Thanks Mystere Man for the answer. For .aspx views it is like this

<script type="text/javascript" src="<%=Url.Content("~/Scripts/jquery-1.10.1.min.js")%>"></script>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top