This project is read-only.


Model-binding collection fails when non-collection property shares a prefix


Given a collection property named "foos" and another property named "foosBar" on an object being model-bound, because of the implementation of the PrefixContainer (specifically the IsPrefixMatch method), if "foosBar" is on a boundary checked by Array.BinarySearch, the algorithm will miss all the collection properties, and the collection will be null after model-binding completes.

I've included failing test in pull request 4032. I'm honestly not sure how to fix this without breaking something else or significantly impacting model-binding performance.

file attachments

Closed Jun 6, 2013 at 12:39 AM by kirthik


HongmeiG wrote Feb 16, 2013 at 12:04 AM

I am assuming this applies to both MVC and Web API. Please let me know otherwise.

bmsullivan wrote Feb 16, 2013 at 10:17 PM

Yes, it does occur in a Web API context as well. I've attached a project that will easily allow you to reproduce the issue. Just open the site root in your browser, and it will make an AJAX request to the ValuesController Post method. You should see the collection property "es" come in to the controller empty. If you comment out the "esSomethingElse" property in the javascript on Index.cshtml that's making the AJAX call, you'll see the "es" property properly populated when entering the Post controller method.