NewCoder1423
NewCoder1423

Reputation: 55

ASP .NET MVC: How to create a Javascript file that contains the functions?

If I understand correctly, I should be creating a Scripts folder in my Solutions Explorer folder, and then adding a javascript file that contains my program.

Then as I require my javascript file in a View, I call

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

Followed by calling the function straight away.

However, this isn't working out for me. If I go to Networks tab of my application, it says could not find name.js at https://localhost:7240/Scripts/name.js. Could someone please let me know what I am missing in my code?

Edit: I used the technique mentioned in the comments and that works.

Please note: If you have made any changes in the code of name.js, it is possible your Google Chrome is still using your old cached version, so ctrl + shift + R and it'll automatically force update the new name.js.

Upvotes: 0

Views: 46

Answers (1)

Yat Fei Leong
Yat Fei Leong

Reputation: 866

Yes it is correct.

enter image description here

Create a script section at the end of your view. The source location refers to the folder under wwwroot/Apps folder as shown below

enter image description here

Upvotes: 1

Related Questions