Last post Feb 17, 2017 10:36 AM by bluMarmalade
Feb 17, 2017 10:20 AM|bluMarmalade|LINK
I want to load a particular set of css and js files in a .cshtml page. I want these to override any other scripts in the _Layout.cshtml
But I also want to keep some of the scripts in the _Layout that deals with the navbar etc.
For some reason all my scripts load perfectly for my index page, but when i go to another page none of my scripts load. I have all links to the scripts in the _Layout.
Even when I put refrences to them into the pages they don't load.
Any ideas? I know this is probably a simple question, but I have little experience with asp.net. Thanks for any help.
Feb 17, 2017 10:23 AM|Dmitry Sikorsky|LINK
The best choice is to use Razor sections for that:
https://docs.microsoft.com/en-us/aspnet/core/mvc/views/layout ("Sections" part).
In short: add optional section for the optional styles and css in your head tag. On the pages that needs some optional styles or scripts define that section and put styles and scripts declarations there. They will be rendered only on that pages.
Feb 17, 2017 10:36 AM|bluMarmalade|LINK
Thanks. I found the error by creating another _Layout for those particular pages.