Shawn
Shawn

Reputation: 509

@Html.JQueryUI() - Does not contain a definition for JQueryUI

I'm sure this is something simple I just can't find it.

In any view that I try and use @Html.JQueryUI().something I'm getting a compile error telling me that JQueryUI does not contain a definition for JQueryUI, and no extension method of type JQueryUI excepts a first argument of type System.Web.MVC.HtmlHelper. I'm asked if I'm missing an assembly reference or using statement.

I have verified that all the required js and css files are being loaded to the page when it is rendered to the browser by looking at the page source, and clicking each of the file links which return the correct file.

In this MVC 4 project I'm using the BundleConfig class to include all css/js files which are these:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                    "~/Scripts/jquery-ui-1.10.4.custom.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.unobtrusive*",
                    "~/Scripts/jquery.validate*"));
bundles.Add(new StyleBundle("~/Content/themes/trontastic/css").Include(
                           "~/Content/themes/trontastic/jquery-ui-1.10.4.custom.css",
                           "~/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"));

I'm rendering the scripts/css in my _Layout page

@Styles.Render("~/Content/themes/trontastic/css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")

JQuery Validate is only rendered on the create and edit view pages.

 @Scripts.Render("~/bundles/jqueryval")

The line of code that returns this error on .JQueryUI() for any view.

@Html.JQueryUI().Datepicker("anotherDate").MinDate(DateTime.Today).ShowButtonPanel(true)

I have verified that all the required js and css files are being loaded to the page when it is rendered in the browser by looking at the page source and clicking each of the file links.

Upvotes: 0

Views: 2503

Answers (3)

Gina Marano
Gina Marano

Reputation: 1803

I ran in to the same problem...

I already had .Net 4.5.1 installed, the web.config was already correct and the dll was already added.

I had to add:

@using JQueryUIHelpers;

Upvotes: 0

dak
dak

Reputation: 199

I'd also recommend to upgrade to .net framework 4.5.1 (http://msdn.microsoft.com/es-es/library/5a4x27ek(v=vs.110).aspx) JQueryUIHelpers didn't work for me until I installed the new version and changed the project application properties to use 4.5.1.

Upvotes: 1

iappwebdev
iappwebdev

Reputation: 5910

You have to add the namespace for JQueryUI HtmlHelper in the webconfig. Open file ~/Views/Web.config and add:

<system.web.webPages.razor>
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
       <namespaces>
           <add namespace="JQueryUIHelpers" />
       </namespaces>
    </pages>
</system.web.webPages.razor>

EDIT

Sometimes you have to close your views or even visual studio to adapt new namespaces in the weg.config

EDIT 2

I just installed this package via nuget. The namespace is added automatically but no so the dll reference. Have a look at your references and add reference for JQueryUIHelpers.dll and rebuild your project. Worked for me.

Upvotes: 3

Related Questions