2020/06/28
ASP.NET MVC内置了jQuery Validation(https://github.com/jquery-validation/jquery-validation)和Unobtrusive Ajax support library for jQuery(https://github.com/aspnet/jquery-ajax-unobtrusive)。我使用的是Visual Studio 2013。因想把Bootstrap的版本升级到最新版4.5.0,也想把jQuery的版本升级到最新版3.5.1,而注意到这两个jQuery插件。
jQuery Unobtrusive Ajax是ASP.NET核心的一部分。从https://github.com/aspnet/jquery-ajax-unobtrusive 下载的的源代码需要构建。但是运行build.cmd失败,不能识别的命令dotnet。原来需要下载 .NET Core,下载地址是:https://dotnet.microsoft.com/download。.NET Core是.NET跨平台的版本,用于创建web站点,服务和应用。
.NET Core Runtime运行应用,.NET Core SDK构建应用。.NET Framework Runtime为运行应用所需,.NET Framework Dev Pack为构建应用所需。
当前,.NET Core的版本是3.1,.NET Framework的版本是4.8。而Visual Studio 2013的.NET Framework的版本是4.5.1。当然,也可以用NET Framework 4.8,只要安装后重启动电脑就行了。
终于构建jQuery Unobtrusive Ajax成功,成功后会生成dist文件夹,在这个文件夹中有两个文件jquery.unobtrusive-ajax.js和jquery.unobtrusive-ajax.min.js。
可以从https://jqueryvalidation.org/下载预建的文件(即源代码和构建后的文件),这是当前发布的稳定版本。
未发布的最新版本可以从https://github.com/jquery-validation/jquery-validation/archive/master.zip 下载,需要自己构建。构建步骤是(https://github.com/jquery-validation/jquery-validation/blob/master/CONTRIBUTING.md#build-setup):
- 安装NodeJS
- 安装Grunt CLI,使用命令
npm install -g grunt-cli - 安装npm依赖,使用命令npm install
- 构建,运行grunt
执行第3步时,提示“Testing test/index.html Warning: Cannot read property 'pid' of undefined Use --force to continue.”改为npm install --force。执行第4步时,提示“Testing test/index.html Warning: Cannot read property 'pid' of undefined Use --force to continue”改为gunt --force。
生成了dist文件夹,包含了两个文件additional-methods.js和jquery.validate.js,还有一个文件夹localization。
本文介绍在ASP.NET MVC中升级jQuery和Bootstrap至最新版本的过程,包括解决构建jQuery Unobtrusive Ajax和jQuery Validation插件时遇到的问题,以及.NET Core与Visual Studio 2013的兼容性解决方案。


被折叠的 条评论
为什么被折叠?



