I have read many topics on how to change the default error message language for form validation, but none are applicable to Net 8 with Razor pages (no MVC). My situation is a webapp in C# with razor pages and I have a simple form with two fields (name, surname) and they are mandatory, I would like the error message to be displayed in a language other than English.
Test.cs
namespace TestNamespace.Data
{
public class Test
{
public string Nome { get; set; } = null!;
public string Cognome { get; set; } = null!;
}
}
Create.cshtml
@page
@model Test.Pages.Test.CreateModel
@{
ViewData["Title"] = "Create";
}
<h1>Create</h1>
<h4>Test</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Test.Nome" class="control-label"></label>
<input asp-for="Test.Nome" class="form-control" />
<span asp-validation-for="Test.Nome" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Test.Cognome" class="control-label"></label>
<input asp-for="Test.Cognome" class="form-control" />
<span asp-validation-for="Test.Cognome" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-page="Index">Back to List</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
I also tried to create a Resources folder in the root containing a DataAnnotations.it.resx file, but this implies that I have to modify all the classes in the project. If I try to write the error message directly into the class, this works, but it is not a desired approach, because I would have to manually edit all the classes.
P.S.: Continuing with the tests, now I also have problems in managing the comma as a decimal separator, while in the validation of the field it generates an error asking me for the point as a decimal separator. The db field is set to decimal (6, 3)

