昨天,今天,明天,每天的每天,你是否都多懂得一点点...

星期三, 八月 15, 2018

[网络技术] ASP.NET MVC Uncaught ReferenceError: $ is not defined

Tags: ASP.NET MVC, jQuery,

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:


#img1#



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 @RenderBody(). 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.

#img2#



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.
#img3#





没有评论:

其它博客地址

此博客的同步博客地址: http://fengnz.wordpress.com
这里进入我的MSN SPACE.