The doc states that a jQuery script is required and cross-links it, but the CreditCardAttribute ref source seems to have the Luhn algorithm implemented and doesn't require the script ...
I would've assumed that jQuery has been factored out by this point in favor of Fetch API. IDK what the framework uses, and I didn't research it further because it seems to no-op in Blazor apps. I assume that this will be discussed with a PU engineer, and I hope that we'll find out why it doesn't work/can't work in Blazor. For now, I've documented that it isn't supported for Blazor.
Although the section correctly starts out by stating that it's for client-side validation, the following remark at the end doesn't cover the limitation well ...
Server side validation also needs to be implemented for clients that have disabled JavaScript.
That's true, but it's always true because [Remote] validation doesn't perform server-side validation at all, even if it's working for client-side checks.
It might also be nice to change that remark to something like ...
Remote validation:
* Doesn't perform server-side validation after the form is submitted.
* Doesn't perform client-side checks if the client has disabled JavaScript.
If the client-side validation check is required for form processing, always implement a separate server-side check.
Description
Noticed a few things to look at for possible updates ...
WRT the model validation article (Built-in attributes section) at ...
https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-8.0#built-in-attributes
The doc states that a jQuery script is required and cross-links it, but the
CreditCardAttribute
ref source seems to have the Luhn algorithm implemented and doesn't require the script ...https://github.com/microsoft/referencesource/blob/master/System.ComponentModel.DataAnnotations/DataAnnotations/CreditCardAttribute.cs
Tested in a Blazor app
EditForm
component, and the credit card validation seems to work fine when only applying the attribute to a model property.There's another jQuery mention for
[Remote]
...https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-8.0#remote-attribute
I would've assumed that jQuery has been factored out by this point in favor of Fetch API. IDK what the framework uses, and I didn't research it further because it seems to no-op in Blazor apps. I assume that this will be discussed with a PU engineer, and I hope that we'll find out why it doesn't work/can't work in Blazor. For now, I've documented that it isn't supported for Blazor.
Also WRT the
[Remote]
coverage ...https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-8.0#remote-attribute
Although the section correctly starts out by stating that it's for client-side validation, the following remark at the end doesn't cover the limitation well ...
That's true, but it's always true because
[Remote]
validation doesn't perform server-side validation at all, even if it's working for client-side checks.It might also be nice to change that remark to something like ...
Page URL
https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-8.0#built-in-attributes
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/mvc/models/validation.md
Document ID
615db388-a244-41f7-21b5-a4085d9ed479
Article author
@tdykstra