ASP.NET MVC ModelBinder calls IValueProvider.GetValue() without check IValueProvider.ContainsPrafix() first

Oct 23, 2014 at 2:27 PM
Edited Oct 24, 2014 at 12:53 PM
As I can see in the source code, the ASP.NET MVC Framework uses a ValueProviderCollection under the hood that implements the IValueProvider-interface. So when the ModelBinder query the ValueProvider, the ValueProviderCollection iterate through all IValueProviders (like Form-, RouteData, QueryStringValueProviderFactory, ...) and returns the first satisfy value:
  • IValueProvider.ContainsPrefix must be true
  • IValueProvider.GetValue must be not null.
Why does the ModelBinder calls IValueProvider.GetValue() although the IValueProvider.ContainsPrafix()-method would returns false?

Why does it makes sense to call IValueProvider.GetValue() when IValueProvider.ContainsPrafix() returns false?

Thanks for any answer!

Edit: I have to say that the issue happens to nested complex-models ("PersonModel.AddressModel.PlaceModel").