-
Notifications
You must be signed in to change notification settings - Fork 2.1k
DataAnnotation validation ignored #3774
Comments
IIRC from digging around in the validation class, this will be because a validation state entry with a key of "AccountId" (case-insensitive) has already been populated. If you place the |
I haven't think of that. You are right, validation works if TransferInfo is first in the signature. |
@rynowak thoughts on this? This seems orthogonally tangentially related to the issue with the cancellation token with regard to the truth of what's in the model state dictionary... |
@rynowak ping |
Yep. This is definitely related to #3743 |
@Eilon - I don't think this is related to my other validation fix. Self-assigning and will fix. |
The issue here is that we don't try to validate something that already appears valid. The idea is to avoid duplicating work when we have a cycle. However, cycles are rare, and validation may depend on the container-object for correctness. The criteria that we're using in this case is the model state dictionary care, which we've seen can definitely overlap between model objects. We should just change this check to proceed if the state is anything other than |
DataAnnotation validation is ignored if route parameter has the same name as object variable passed in the body of the HTTP request
Model:
Controller:
Posted data (JSON):
ModelState is valid even if I check that accountId must be greater than 0, using Range or Custom validation attribute.
If I update my TransferInfo class definition and rename "AccountId" by "ToAccountId" and try to send:
ModelState Validation will failed
The text was updated successfully, but these errors were encountered: