I have a layout with an @RenderSection("scripts") section and I have a bundle that would need to be included in this section for some views. I thought that just doing this in the view would work, but it’s not rendering the scripts.
@section scripts {
@Scripts.Render("~/bundles/myBundle")
}
In my view, how can I include a bundle to the scripts section?
Layout
@Scripts.Render("~/bundles/jquery", "~/bundles/scripts")
@RenderSection("scripts", required: false)
View
@section scripts {
@Scripts.Render("~/bundles/movie")
}
Why mix the rendersection with bundling? If you choose to down the route of bundling, you can simply put your scripts in .JS file ,put it in their own bundle if you like and call that bundle on your view. For ex:
then view will have the following:
Also make sure your Web.config has compilation debug set to false like below:
it makes sure the scripts are bundled and minified.
Update
Based on comments and my recent experience, I can see why would we want to use the two together. Perfect case of learning in the community! 🙂 So, if you decide to come back for refactoring, I would make sure there are no typos to begin with. If it still does not work, please let me know what the problem is and I will update the answer accordingly. Thanks everyone!