0

I'd like in an .cshtml page, insert an .js page.

I tried this :

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

No problem with the same code in the shared/_layout.cshtml (in the header section)

When I execute the application, this file is not present in the source code (not include).

Any idea ?

Thanks,

3
  • What's the response httpCode? Look using a web developer tool like Firebug in Firefox or Developer Tool in Chrome. Commented Feb 12, 2012 at 15:25
  • Is the script block included in your source code? Commented Feb 12, 2012 at 15:28
  • The response is correct but the js is not in Commented Feb 12, 2012 at 15:36

2 Answers 2

1

try:

<script src="@Url.Content("../../Scripts/MyFile.js")" type="text/javascript"></script>
Sign up to request clarification or add additional context in comments.

2 Comments

I used Areas, then I tried several level of ../../.. but same
@Kris-I did you try "/scripts/MyFile.js" without ~?
0

Your code is correct (assuming you are using Razor templating in MVC3). The only way this would not work is if the path to your script is wrong.

2 Comments

yes with razor :) The .js is in the same folder than the others. But the others are called from /shared/_layout.cshtml
The ~/ in the Url means that the path should be relative to the root of your solution - is this definitely using the right path?

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.