I have a .net 7 Razor page application and for the life of me cannot get the Jquery to load and work. It has stalled my project and am really looking for some guidance. The artical I found uses startup.cs but core 7 no longer has the file.
Please advise and thank you in advance,
Steve
Deepak RawatPosted Jul 4, 2023, 5:23 AM
Add the necessary references: Open your
_Layout.cshtmlfile (or any other layout file you are using). Add the following code within thesection to reference the jQuery libraryWrite your jQuery code: In the
site.jsfile, write your jQuery code.Include the JavaScript file: In your
_Layout.cshtml(or any other layout file), add the following code at the bottom, just before the closingtag:Build and run your application: Save the changes, build your application, and run it. The jQuery code should now be loaded and executed when the corresponding page is rendered
Tuhin PaulPosted Jul 4, 2023, 2:04 AM
In latest .Net Version, the startup configuration has been simplified with the introduction of a new minimal API project template. You can still configure jQuery in your Razor Pages application. Here's how you can do it:
1. Add jQuery to your project:
- Open the NuGet Package Manager Console.
- Run the following command to install the jQuery package.
2. Check jQuery is included in your project:
` section:- Open your Razor Pages layout file (typically `_Layout.cshtml`).
- Check if the following line is present within the `
- If the line is not present, add it to include the jQuery library. Make sure the path is correct based on your project structure and the location of the jQuery package.
3. Verify your JavaScript/jQuery code:
- Verify that your JavaScript/jQuery code is properly written and does not have any syntax errors.
- Check that the selectors you are using in your jQuery code are correctly targeting the desired elements in your HTML.
Prasad RaveendranPosted Jul 4, 2023, 12:30 AM
refer the below link. This may help you
https://learn.microsoft.com/en-us/aspnet/core/mvc/views/layout?view=aspnetcore-7.0