Reputation: 41
In this tutorial : Building your first ASP.NET Core MVC app with Visual Studio the purpose is to build a simple movie application. At step Adding a model there is this note below :
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.
But I did not found in the mentioned additionnal resources how to integrate jQuery for date / decimal inputs when using non English locale.
This is well explain in this tutorial : Getting started with ASP.NET MVC 5 at step 7 Examining the Edit Methods and Edit View (near the end of the page). Actually it is the same tutorial but targeting ASP.NET MVC, not ASP.NET CORE MVC.
I tried to follow the same steps but I am stuck because the _Layout view in ASP.NET CORE MVC tutorial cannot be set the same way than in ASP.NET MVC tutorial.
Do you know how to Integrate the jquery Globalize js package into an ASP.NET Core MVC web App ? Or better can you translate the concern part of the ASP.NET MVC tutorial into ASP.NET CORE MVC way ?
Upvotes: 4
Views: 1869
Reputation: 106
After struggling many hours I finally found the solution (credits for this page http://www.tiselvagem.com.br/desenvolvimento/net/validacao-de-data-e-moeda-asp-net-mvc-jquery-validation-em-portugues/ in Portuguese).
Solution:
Add the methods_XX file (XX stands for the language to your project - in my case methods_pt.js) and then change _ValidationScriptsPartial.cshtml file in the Views/Shared folder to include the added file. In my case:
<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>
Upvotes: 2