MVC 4 Razor and JQuery UI datepicker () "Object does not support property or method"

I probably just spent the last two hours trying to figure it out.

The specific error that occurs with my MVC application is: "0x800a01b6 - JavaScript runtime error: the object does not support the property or method 'datepicker'"

Here is my code:

_Layout.cshtml:

<head> ... <script type="text/javascript" src="../../Scripts/jquery-2.0.3.js"></script> <script type="text/javascript" src="../../Scripts/jquery-ui-1.10.3.js"></script> </head> 

view .cshtml

 @{ ... Layout = "~/Views/Shared/_Layout.cshtml"; } ... <div> Change Time Span: <br /> From: <input type="text" id="test" /> </div> <div class="loading" id="container">@Model.LoadingMessage</div> <script type="text/javascript"> $(document).ready(function () { $('#test').datepicker(); }); </script> 

I looked at some potential β€œduplicate” issues without success. Here are some of the questions I have addressed:

Error viewing the MVC3 firewall. Microsoft JScript runtime error: the object does not support the jquery datepicker property or method giving the error "The object does not support this property or method" by the datepicker method. Using datepicker in MVC 4.0 to save the date value in db, throwing object does not support this property or method "

  • I believe that I am referencing everything I need from jquery to achieve my goal.
  • The element is read from jQuery, it can see its value if I set it, so I don’t think my selector is a problem.
  • Both jQuery packages were installed through NuGet (the latest version of jQuery and the unified jQuery UI library).
  • I restored / cleaned up the Visual Studio solution (in desperation), disconnected the local IIS host and reset it ...

What am I missing? Intellisense even detects that the method exists, and gives me suggestions on why the parameters need to be entered.

Is there something simple that I missed?

+6
source share
5 answers
 Required scripts ---------------- <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" /> <script src="@Url.Content("~/Scripts/jquery-1.9.1.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery-ui-1.10.0.js")" type="text/javascript"></script> <p>Date:<input type="text" id="Dob" class="datefield" /></p> <script type="text/javascript"> $(document).ready(function () { $("#Dob").datepicker({ changeMonth: true, changeYear: true }); }); </script> 
+5
source

I found that by commenting on "@ Scripts.Render (" ~ / bundles / jquery ") at the bottom of _Layout.cshtml, I was able to solve the problem with this.

+12
source

Have you verified that you referenced jquery twice? I found that I included it in my layout and, in my opinion. Removing one link resolved the issue.

+4
source

Try the following:

  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 

or that:

  <script" src="~/Scripts/jquery-ui-1.10.3.js"></script> 

Instead of this:

  <script type="text/javascript" src="../../Scripts/jquery-ui-1.10.3.js"></script> 
+2
source

I had this problem when upgrading to jQuery 2. I was noticed by changing the folder structure in jQuery download; the jquery-ui.js file was no longer in the ui folder, so the script tag was not displayed correctly.

So double check the links are correct.

+1
source

Source: https://habr.com/ru/post/956037/


All Articles