ASP.NET MVC Uncaught ReferenceError: $ is not defined

  • fennng 

When a ASP.NET MVC project is created in Visual Studio 2017, Jquery is
built in. But when you try to use jQuery in the index.cshtml file, you will
get the following error:

The wield thing here is that Visual studio’s template imports jquery script
after @RenderBody(). The code you write in index.cshtml is rendered by
(). But as this happen before jQuery is imported, you get the $
is not defined error.

To fix this issue, you will have to move this code into the head section.


Note that, .NET MVC doesn’t have jQuery UI by default, if you want to use

any jQuery UI function, don’t forget to import jQuery UI.

The following example use jQuery UI from jQuery CDN.


您的电子邮箱地址不会被公开。 必填项已用*标注