The code you see for rendering CSS and scripts on your _Layout.cshtml page (i.e. @Scripts.Render("~/bundles/modernizr") ) is called packaging . Check out some information here: http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification
So, to add jQueryUI, you have to do the following:
In your Global.asax.cs file, you should see several registrations:
BundleConfig.RegisterBundles(BundleTable.Bundles);
This refers to the BundleConfig class which registers any packets. For jQueryUI you can do the following:
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include( "~/Scripts/jquery-ui-{version}.js"));
This creates a new script package named ~/bundles/jqueryui .
Then it can be added to the layout page by doing this:
@Scripts.Render("~/bundles/jqueryui")
Then you will do the same for CSS:
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include( "~/Content/themes/base/jquery.ui.core.css", "~/Content/themes/base/jquery.ui.resizable.css", "~/Content/themes/base/jquery.ui.selectable.css", "~/Content/themes/base/jquery.ui.accordion.css", "~/Content/themes/base/jquery.ui.autocomplete.css", "~/Content/themes/base/jquery.ui.button.css", "~/Content/themes/base/jquery.ui.dialog.css", "~/Content/themes/base/jquery.ui.slider.css", "~/Content/themes/base/jquery.ui.tabs.css", "~/Content/themes/base/jquery.ui.datepicker.css", "~/Content/themes/base/jquery.ui.progressbar.css", "~/Content/themes/base/jquery.ui.theme.css"));
and add it with
@Styles.Render("~/Content/themes/base/css")
Remarks:
- In MVC4, jQuery is already configured for a non-empty project. For an empty project, you must add it yourself. Not 100% sure about the new MVC 5.
- You can install jQueryUi from NuGet, but the official package does not add this package.
- You can just make old-fashioned links to your CSS and JS files (for example,
<script language="JavaScript" src="~/Scripts/jQuery.ui.1.8.2.js"/>
Simon C Nov 19 '13 at 21:00 2013-11-19 21:00
source share