dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.55k stars 25.31k forks source link

Possible validation doc updates #33239

Open guardrex opened 1 month ago

guardrex commented 1 month ago

Description

Noticed a few things to look at for possible updates ...

  1. 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.

  2. 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.

  3. 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 ...

    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.

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

tdykstra commented 1 month ago

@mkArtakMSFT Who can help with this model validation issue from @guardrex?