ASP.NET Core has beautiful way of handle valiadtion. But the validation style showing in frontend is very old school. The way i have followed:
Custom model annotation with error message:
[Required(ErrorMessage = "UserName is Required")]
[StringLength(10, ErrorMessage = "Must be between 5 and 10 characters", MinimumLength = 5)]
[UserNameVal]
public string UserName { get; set; }
add script for showing message in view
@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
Showing error message with span:
<span asp-validation-for="@Model.UserName" class="text-danger"></span>
And this is resulting a primitive old faishon validation message like the screenshot below
But I want validation style like this with using the default asp-for-validation
Is it possible without writing extra javascript in every page? if possible then how? I have already explored these links: https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-3.1 http://jsfiddle.net/2DUX2/ https://www.codeproject.com/Tips/755421/Using-the-jQuery-unobtrusive-validator-with-Twitte