Skip to content

Check ModelState.IsValid by Default #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jaredcnance opened this issue Apr 5, 2018 · 0 comments
Closed

Check ModelState.IsValid by Default #252

jaredcnance opened this issue Apr 5, 2018 · 0 comments

Comments

@jaredcnance
Copy link
Contributor

Gitter transcript:

Kevin Sigmund @ksigmund Mar 26 08:49
If I have a custom ValidationAttribute that returns false, will the error naturally be returned in the result from the controller, or do I need to override PostAsync, check the ModelState, etc.?

Kevin Sigmund @ksigmund Mar 26 09:22
Basically I'm just looking to do simple model validation, but it doesn't seem that when my model is invalid that the failure is respected.

Jared Nance @jaredcnance Mar 26 10:05
We do not currently check ModelState.IsValid ... I don't want to make any assumptions about how model validation is implemented. However, I'm open to discussion and with a little more information I think it may be reasonable to do that in the library automatically (while providing some form of escape hatch). My main concern would be around not making any breaking changes without good reason.

Kevin Sigmund @ksigmund Mar 26 10:09
Right now it seems that the framework is fairly optimistic about the state of the model right? i.e. without any additional logic, failures are ignored essentially.

Jared Nance @jaredcnance Mar 26 10:12
As long as it passes de-serialization, we perform no further model validations. That said, we also shouldn't be preventing any model validations in custom controllers. Is model validation something you believe should be handled by the framework by default?

Kevin Sigmund @ksigmund Mar 26 10:16
I think so - and I believe that's the way that the .NET Core framework is moving as well.
It seems like if I have a [Required] or [SomeOtherValidation] attribute if the validation fails, something is wrong and I probably don't want to ignore that. Maybe it's some sort of config at setup where we could instruct the framework to respect validations.

Jared Nance @jaredcnance Mar 26 10:18
I agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant