views:

131

answers:

1

I'm not sure if this is a bug, or a feature. I have an action param that takes a ListRequest object with a few string properties. .NET MVC dutifully maps the query string params of the same name to the ListRequest objects' properties.

I add a ListRequest.Filters property, which is to be a list of strings taken from the querystring: ?filter=foo&filter=bar

If I declare .Filters as a Get/Set of type List(Of String), DefaultModelBinder does exactly what you would expect. However, if I declare .Filters as a Get/Set of IList(Of String) instead, DefaultModelBinder stops binding values to that property completely.

Is this a feature, or a bug?

A: 

Sounds like a feature to me. The model binder needs concrete types to bind to.

If you tell it to bind to an interface it can't do anything because it can't instantiate an interface to bind to.

EDIT: Interesting

Judging by the source code, it seems that it will bind to a model that is a generic type of IEnumerable, ICollection, IList or IDictionary BUT it won't bind on a model's property that is of a generic type.

So I wouldn't say it's a bug... I'd just say that it's a feature that they have overlooked. :-)

Charlino
But that's not entirely true.If my action had a param of (filters As IList(Of String)), it actually works. So clearly the default model binder is already making some assumptions about how to populate IList(Of T) from querystring/form.
claco