Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include script bundle in scripts section in view

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")   } 
like image 406
bflemi3 Avatar asked Dec 01 '12 15:12

bflemi3


People also ask

What is scripts bundle js?

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.

HOW include script in MVC application?

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.

How do you use bundling and minification in MVC 5?

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.


1 Answers

Try below mentioned solution inside the View.

View

@section Scripts{     <script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/movie")"></script> } 
like image 197
Sampath Avatar answered Oct 05 '22 17:10

Sampath