Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Validation incorrect for dynamic collections when using TryUpdateModelAsync() #2941

Closed
dougbu opened this issue Aug 9, 2015 · 1 comment
Closed
Assignees
Milestone

Comments

@dougbu
Copy link
Member

dougbu commented Aug 9, 2015

The problem described in #2294 has been fixed for controller properties and action parameters. Unfortunately that problem remains when using TryUpdateModelAsync(). The following form data (an example from #2294) will not be correctly validated because the IObjectModelValidator will not be informed that model nodes collection[key1] or collection[key2] exist.

Collection.index = key1,key2
Collection[key1].Name = name1
Collection[key2].Name = name2

Root cause: ModelBindingHelper.TryUpdateModelAsync() completely ignores the ModelValidationNode tree the model binding system returns, passing a new ModelValidationNode instance to the IObjectModelValidator. This method does not even check ModelBindingResult.IsModelSet before using ...Model.

(noticed while investigating #2633)

@danroth27 danroth27 added this to the 6.0.0-beta8 milestone Aug 12, 2015
dougbu added a commit that referenced this issue Aug 21, 2015
…ing elsewhere

- #2941
- honor `ModelBindingResult.IsModelSet` and use `ModelBindingResult.ValidationNode`
  - enable correct validation of collections or after model binding falls back to the empty prefix
  - code previously matched `Controller.TryValidateModel()`; less context available in that case
@dougbu
Copy link
Member Author

dougbu commented Aug 21, 2015

02cc82a

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants