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

Invalid dynamic collection binding and validation #2294

Closed
@anfomin

Description

@anfomin

@dougbu asked to create new issue in discussion #2268. Current CollectionModelBinder can't properly bind collections with dynamic indexes. It returns invalid results in 2 cases.

1. I've class with collection property:

class RootObject
{
    public IList<AnotherObject> Collection { get; set; }
    // other code goes here
}

class AnotherObject
{
    public string Name { get; set; }
}

Binding form data:

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

If I try to bind RootObject then Collection property is bound successfully, but ModelState contains unvalidated states for Collection[key1].Name and Collection[key2].Name:

var model = new RoomObject();
TryUpdateModel(model);
/// ModelState.IsValid returns false - wrong value.

2. I've the same classes. If I try to bind collection of AnotherObject directly with prefix, result collection is still empty:

var collection = new List<AnotherObject>();
TryUpdateModel(collection, "Collection");
// collection is still empty, even if there is data

I'm using latest beta5 MVC version.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions