Problem using jQuery UI in ASP.NET MVC

Asked

Viewed 164 times

0

I am trying to add the jQuery UI "Autocomplete Combobox" to my ASP.NET MVC project, but it says that the widget function is not a function.

jquery-3.1.1.min. js: 2 jQuery.Deferred Exception: $.widget is not a Function Typeerror: $.widget is not a Function

I’m following the example of jQuery’s website (jQuery UI tutorial), the difference is that I extracted the scripts for external file and the css as well.

I have already linked the scripts needed to use this function, which is in the following order:

<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/jquery-ui.css")">
<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/app/cliente/meu-css.css")">

<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-3.1.1.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-ui.min.js")"></script>

<script type="text/javascript" src="@Url.Content("~/Scripts/app/cliente/meu-script.js")"></script>

I repeated this example in the notepad and it worked, but in the MVC project it did not work.

  • You have some problem loading the JS that has the widget function, check the JS loaded in the page to know which one was not loaded

  • Ricardo, all were loaded, including the jquery-ui.js that contains the function. I don’t understand this. :(

1 answer

0


I managed to find the problem!

Even though jQuery was loaded first, my script could not find the function, as I was not passing the '$' in the parameter function of my script:

(function($){
    $(document).ready(function(){
        $.widget("custom.combobox", {
        ...
    });
})();

I still don’t understand why, in this case, my script can’t see jQuery without having to pass the '$' in the parameter , and when I did this same example in the notepad did not need to do this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.