-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Ignore validation of model property #4143
Comments
You can do this on RC2 by implementing something similar to https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationExcludeFilter.cs And then
This is the mechanism the framework uses to avoid validation recursing into types like The reason you would need to write your own class is that the build in |
Thanks. Is attribute based ignore filter in plans or |
Yeah, you're right, this isn't really exactly what you're looking for. Reopening. |
Not planned for this release. |
As I understand I can override Also, I was wondering I maybe there is a way to affect further validation by editing As a note, we still use RC1 as RC2 is not released yet. |
Hullo, I've just found this issue and am facing the same problem.
ASP.NET Core 1.0.0 ( Hitting the same validation visitor trying to get the value of my Optional class and getting an exception thrown at it:
From my Value getter:
Is there any update on how to customise the Kind regards, |
Yes, ignore services.AddMvc(options =>
{
options.ModelMetadataDetailsProviders.Add(
new SuppressChildValidationMetadataProvider(typeof(Optional)));
}); |
But this will ignore all validation of |
Your question was
My answer was "yes". If you want to go further, combine the suppression with custom validation of the |
Closing this bug in favor of #5642, which covers the broader scenarios. |
Hello,
For implementation of
PATCH
method where I need to distinguish between property being null or not set, e.g.{"key": null}
vs{}
.I have a following model (see below) used to define optional json properties similar to null-able, but it can take any type.
It works for deserialization in tests, but when used inside controller method, then an
InvalidOperationException
is thrown before my code even runs, becauseValidationVisitor
from framework iterates over public properties of my model and hits Value property of instance withIsSet==false
, which leads to exception.Is there a way to tell
ValidationVisitor
to ignore certain property or define a custom validation property?Here is a stack-trace (minor parts of it is in Russian)
The text was updated successfully, but these errors were encountered: