jquery - Insert javascript file in cshtml page - Stack Overflow

I'd like in an .cshtml page, insert an .js page.I tried this :<script src="@Url.Content(&q

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745492160a4630033.html

相关推荐

  • jquery - Insert javascript file in cshtml page - Stack Overflow

    I'd like in an .cshtml page, insert an .js page.I tried this :<script src="@Url.Content(&q

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信