Zubzob
Zubzob

Reputation: 2743

Script loaded from the _Layout not found

I'm loading some scripts in the _Layout.cshtml page at the bottom of it:

<script src="~/scripts/jquery-1.8.2.min.js"></script>
<script src="~/scripts/easing.js"></script>
<script src="~/scripts/bootstrap.js"></script>

@RenderSection("scripts", required: false)

but for some reason, it won't load the jquery file. The easing and bootstrap script files will be loaded though: enter image description here

If I exclude jquery from the _Layout.cshtml page, it will fail to load the easing.js file (which was loaded previously): enter image description here

I'm going nuts as I can't figure out what's going on. Does anyone ever encountered such behavior or am I doing something wrong?

Upvotes: 0

Views: 938

Answers (1)

Tommy
Tommy

Reputation: 39807

It appears the parser is struggling with the first ~ in the list (looking at the generated path coming from Chrome.) It could be a markup error earlier in your layout file or something else entirely - hard to say with the info provided. Typically, we use the Url.Content() helper instead of the raw ~ string in our script and style tags without issue.

I would recommend updating your <script> tags with a little bit more information.

  1. Add the type to the script tag.
  2. Try using the @Url.Content() html helper to see if that helps render the correct link.

This would be the resulting tag

<script type="text/javascript" src="@Url.Content("~/scripts/jquery-1.8.2.min.js")"></script>

Upvotes: 2

Related Questions