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") }
scripts.bundle.js represents scripts section that you configured in .angular-cli.json. vendor. bundle. js contains npm modules you are referencing in your app.
Go to Views -> Shared -> _Layout. cshtml file and add the render code. Make sure to register the custom javascript file after the jquery bundle since we are going to use jquery inside our js file. Otherwise we will get a jquery error and also register this before the script RenderSection.
To enable bundling and minification, set the debug value to "false". You can override the Web. config setting with the EnableOptimizations property on the BundleTable class. The following code enables bundling and minification and overrides any setting in the Web.
Try below mentioned solution inside the View.
View
@section Scripts{ <script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/movie")"></script> }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With