-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Need better way to suppress validation of properties/types during model binding #5642
Comments
@dougbu let's discuss with @rynowak and @danroth27 when everyone is back in the office. |
I would also be great to have an Problem might be how to determine the "placeholder"-object from invalid objects. Edit: Unrelated - could you provide me some documenation on how to (if possible) override indexing for collections during model binding phase? I'm creating entries client side ideally I would like to just have i guid or something as name/index instead of consecutive integers since maintaining those in consecutive order is a pain :) |
@joacar can you log this in a new issue so we can discuss it separately? |
(Actually, probably two new issues because it seems like you have two separate topics. Thanks!) |
FYI a public interface IShouldValidate
{
/// <summary>
/// Gets an indication whether the <paramref name="entry"/> should be validated.
/// </summary>
/// <param name="entry"><see cref="ValidationEntry"/> to check.</param>
/// <param name="parentEntry"><see cref="ValidationEntry"/> containing <paramref name="entry"/>.</param>
/// <returns><c>true</c> if <paramref name="entry"/> should be validated; <c>false</c> otherwise.</returns>
bool ShouldValidateEntry(ValidationEntry entry, ValidationEntry parentEntry);
} is an alternative to the approach I've taken so far on this bug for dynamic validation decisions. The more I think about it, the more I like it. Would reduce the number of classes users need to write and would avoid DI replacements. Even better, would be possible for But So, you'd either need to apply your |
@dougbu Could you point me to some implementation of using that technique? Sounds promising |
- #5642 - lazy-load `ValidationEntry.Model` - avoids `Exception`s when moving to a property that will not be validated nits: - remove duplicate code in `ValidationVisitor` - clarify "all properties of" doc comments - also add missing `<param>` doc in `ViewDataInfo`
- #5642 - lazy-load `ValidationEntry.Model` - avoids `Exception`s when moving to a property that will not be validated nits: - remove duplicate code in `ValidationVisitor` - clarify "all properties of" doc comments - also add missing `<param>` doc in `ViewDataInfo`
Great, thanks. Will check it out |
Today it is not easy to statically disable validation explicitly on a particular property of a particular type. It also isn't as easy as it could be to disable validation on a type (it is possible to do today, but perhaps not as easy as it could be).
See related: #5633 (Model binding, BindNeverAttribute and BindAttribute ignored ?)
It is also not easy to decide whether to disable validation of a property at runtime.
See related: #4143 (Ignore validation of model property)
We should come up with a simple solution for the first problem, e.g. a new
[ValidateNever]
attribute (attribute applies to property + type), and perhaps take a look at how to disable validation dynamically a possibility.The text was updated successfully, but these errors were encountered: