0

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.

    1 Answer 1

    1

    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

    7
    • Hi, sorry, I'm still a bit unclear about this, this worked in getting the program.js being detected by my Network, but I still can't access the function inside of it, I am directly calling it by name, is there anything else that I need to call it? And now I am also seeing this in my console: Uncaught SyntaxError: Unexpected identifier 'dateDifference' where dateDifference was used in the first line of the js file like this: function HowOld(String dateDifference)CommentedFeb 19 at 0:04
    • Then it looks like your function problem. Could you share ur js code and how u call the function from ur view?CommentedFeb 19 at 12:42
    • Hi, I added the code as edits in my post, thank you very much!CommentedFeb 20 at 5:47
    • I give u a sample later on how to write in the script fileCommentedFeb 20 at 10:33
    • Okay okay, thank you very much, I appreciate all the help!CommentedFeb 22 at 8:24

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.