First of all, none of the styles or scripts included in the BundleConfig will be loaded if it is not included in the view by calling the Scripts.Render () or Styles.Render () methods. By default, these methods are called on the _Layout.schtml (Views / Shared) page.
@Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/bootstrap")
Creating another layout page for the admin area and loading the necessary scripts and styles would be the best option.
You can also load them from any .cshtml (view) file using the same method, Scripts.Render (). In this case, it will look like
@{ if (User.IsInRole("Admin")) { //Update this portion with path of required bundles @Scripts.Render("~/bundles/jquery") } else { //Update this portion with path of required bundles @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/jqueryval") } }
The above snippet can be added either to the _Layout page, or to any other page.
And if the requirement is to add some disparate code. Just use the script tag. What would look like this:
@{ if (User.IsInRole("Admin")) { //required script or style files } else { //To include unbundled and unminified scripts <script type="text/javascript" src="~/Scripts/jquery.validate.js"></script> } }
source share