Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: Bug in MVC4: System.Web.PrefixContainer [616]

$
0
0
It seems that internal System.Web.PrefixContainer class was introduced in MVC4 and this class has the bug, which is reproduced with the following model, view and controller action method: <br /><br />public class Model<br />{<br /> public Model()<br /> {<br /> Value = new List<Item>();<br /> }<br /><br /> public string SomeData { get; set; }<br /><br /> public string ValueIsSequence { get; set; }<br /><br /> public class Item<br /> {<br /> public string Data { get; set; }<br /> }<br /><br /> public List<Item> Value { get; set; }<br />}<br /><br />@using (Html.BeginForm())<br />{<br /> <input type="text" name="SomeData" value="123" /><br /> <input type="text" name="ValueIsSequence" value="True" /><br /> <input type="text" name="Value[0].Data" value="ABC" /><br /><br /> <button type="submit">OK</button><br />}<br /><br />[HttpPost]<br />public ActionResult Testing(Model model)<br />{<br /> var failed = model.Value.Count == 0;<br /> return View();<br />}<br /><br />The bug is that Model.Value list is empty and "Value[0].Data" form field is skipped. Prefix matching fails while checking "Value" prefix (for the Model.Value property) and probing "ValueIsSequence" field in binary search: "Value" is not equal to "ValueIsSequence" of course, and then the PrefixContainer supposed (incorrectly) that field can only be "Value." or ""Value[", but it detects "ValueIsSequence" that does not match "Value." nor "Value[", the comparer returns -1 (less) and binary search is moving to less half to probing "SomeData" field. So the binary search never detects "Value[0].Data" and Model.Value stays not filled. <br /><br />Renaming "ValueIsSequence" to "IsSequence" for example, is a possible workaround. <br />
Comments: I have created a package to fix this issue. Just see this blog post. http://weblogs.asp.net/imranbaloch/archive/2012/12/08/fixing-model-the-binding-issue-of-asp-net-mvc-and-asp-net-web-api.aspx

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>