I had seen the call to RenderSectionAsync but did not realize what it was doing. The key was putting the script inside the Scripts block. Now that I have everything organized correctly, it is working and I understand why!!! Next, I moved the links and references to a header section on the razor page and it still did not work. It is so confusing to add the links and script references to the _Layout.cshtml file only to have it not work as expected. None of the examples explain how the _Layout.cshtml file works in relation to the Razor views in an application. I have gotten a few examples to work but, until now, I had no idea why something worked or did not work.Īll of the examples I have looked at online show the references to. I am new to JavaScript/jQuery and have been trying to get jQuery scripts to work for over two weeks now. Thanks to everyone who contributed to these answers. Into, should look like this: - required: false) As already mentioned this is because jQuery is loaded after the rest of the page content.įix this by navigating to Pages\Shared\_Layout.cshtml and add the scripts section to the html head tag instead. Net Core 2.2 - Web Application with Razor Pages and try to add a jQuery script in index.cshtml you will get the error Uncaught ReferenceError: $ is not defined.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |