asp.net-core-mvc – 将jquery-globalize集成到ASP.NET Core MVC应用程序中

在本教程中:使用Visual Studio构建您的第一个ASP.NET Core MVC应用程序,目的是构建一个简单的电影应用程序.在步骤
Adding a model,有以下注释:

Note

You may not be able to enter decimal points or commas in the Price
field. To support jQuery validation for non-English locales that use a
comma (”,”) for a decimal point, and non US-English date formats, you
must take steps to globalize your app. See Additional resources for
more information. For now, just enter whole numbers like 10.

但是我没有在上面提到的附加资源中找到如何在使用非英语语言环境时集成jQuery用于日期/小数输入.

本教程中有很好的解释:在步骤7 Examining the Edit Methods and Edit View(靠近页面末尾)开始使用ASP.NET MVC 5.
实际上它是相同的教程,但针对ASP.NET MVC,而不是ASP.NET CORE MVC.

我试图遵循相同的步骤,但我被卡住了,因为ASP.NET CORE MVC教程中的_Layout视图不能像ASP.NET MVC教程中那样设置.

您知道如何将jquery Globalize js包集成到ASP.NET Core MVC Web App中吗?或者你能更好地将ASP.NET MVC教程的关注部分转换为ASP.NET CORE MVC方式吗?

最佳答案 经过几个小时的努力,我终于找到了解决方案(本页为
http://www.tiselvagem.com.br/desenvolvimento/net/validacao-de-data-e-moeda-asp-net-mvc-jquery-validation-em-portugues/的葡萄牙语).

解:

添加methods_XX文件(XX代表项目的语言 – 在我的例子中是methods_pt.js),然后在Views / Shared文件夹中更改_ValidationScriptsPartial.cshtml文件以包含添加的文件.就我而言:

<environment names="Development">
    <script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
    <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
    <script src="~/lib/jquery-validation/methods_pt.js"></script>
</environment>
<environment names="Staging,Production">
    <script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js"
        asp-fallback-src="~/lib/jquery-validation/dist/jquery.validate.min.js"
        asp-fallback-test="window.jQuery && window.jQuery.validator"
        crossorigin="anonymous"
        integrity="sha384-Fnqn3nxp3506LP/7Y3j/25BlWeA3PXTyT1l78LjECcPaKCV12TsZP7yyMxOe/G/k">
    </script>
    <script src="https://ajax.aspnetcdn.com/ajax/jquery.validation.unobtrusive/3.2.6/jquery.validate.unobtrusive.min.js"
        asp-fallback-src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
        asp-fallback-test="window.jQuery && window.jQuery.validator && window.jQuery.validator.unobtrusive"
        crossorigin="anonymous"
        integrity="sha384-JrXK+k53HACyavUKOsL+NkmSesD2P+73eDMrbTtTk0h4RmOF8hF8apPlkp26JlyH">
    </script>    
    <script src="~/lib/jquery-validation/methods_pt.js"></script>
</environment>
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞