最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Insert javascript file in cshtml page - Stack Overflow

programmeradmin1浏览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,

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,

Share Improve this question asked Feb 12, 2012 at 15:22 TheBoubouTheBoubou 20k54 gold badges151 silver badges250 bronze badges 3
  • What's the response httpCode? Look using a web developer tool like Firebug in Firefox or Developer Tool in Chrome. – Acaz Souza Commented Feb 12, 2012 at 15:25
  • Is the script block included in your source code? – Martijn Commented Feb 12, 2012 at 15:28
  • The response is correct but the js is not in – TheBoubou Commented Feb 12, 2012 at 15:36
Add a ment  | 

2 Answers 2

Reset to default 1

try:

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

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.

发布评论

评论列表(0)

  1. 暂无评论