We are making a .Net MVC websolution that is going to be using widgets rendered as HTML.Partials(). We would like to be able for the partial view to add its dependencys in t
It just seemed to be specific to my jquery bundle. It now works, I have added a widgetspecific bundle where you can add scripts to render in the main layout. The bundle also handles the adding of the same file several times (which can happen if the same widget exists several times on the same page) and only renderes it once. My solution added below, which doesnt seem to be that well documented from the searches Ive done so far.
In BundleConfig.cs:
bundles.Add(new ScriptBundle("~/widgetspecific"));
In _Layout.cshmtl:
@Scripts.Render("~/widgetspecific")
In Widget.cshtml:
@{
var bundle = System.Web.Optimization.BundleTable.Bundles.GetBundleFor("~/widgetspecific");
bundle.Include("~/Scripts/andreas.js");
}
Is anyone aware of negative aspects to this solution?
You would need to create a new bundle for each widget, otherwise if you re-use the "~/widgetspecific" bundle it will continue to add the scripts from the previous page's widget as you navigate through your site.
@The Kaizer, For you own answer above. In Widget.cshtml you might want to use
var bundle = System.Web.Optimization.BundleTable.Bundles.GetBundleFor("~/widgetspecific");