Some of my views require jQueryUI, some do not.
Rather than adding logic to my _Layout.cshtml Razor view, what is the best way to conditionally add certain bundles.
Try to use the @section directive.
In your Layout.cshtml:
<head> @Scripts.Render("~/bundles/jquery") @RenderSection("CustomScripts", false) </head> Then somewhere in your View:
@section CustomScripts { @Scripts.Render("~/bundles/jquery.ui") @Scripts.Render("~/bundles/jquery.templates") } This way even if you set CustomScripts later in your view, it will always appear in the head tag.
Just put the script link at the bottom of the views that need it?
@Scripts.Render("~/bundles/jqueryui")