I use
list binding in my ASP.NET MVC applications in several places. When it works, it is truly magnificent. When it doesn't, it's just maddening. Here's a quick heads up for those of you that use list binding in MVC. You would expect the following 2 lines to render the same HTML, but they don't. To get list binding to work, you need the HTML to read something like this (I'm just listing the attributes in question here):
<input name="Results[0].Score" />
The old TextBox helper works fine, since you're assigning the name attribute:
Html.TextBox("Results["+id+"].Score", Model.Score)
This code, however:
Html.TextBoxFor(r => r.Score, new { name = "Results[" + id + "].Score" })
produces the following output, which means the Score property won't get bound properly.
<input name="Score" />
The problem is that in the TextBoxFor code, the name attribute is ignored. To be more precise, the custom name is added, but the attribute is then replaced by the name derived from the model.