I have the below code in a view. (index.cshtml)
Binding Problem
- The first drop down selects the correct value, based on the 'ChildItem' editor template.
- The second example using an inline drop down list does not work I don't want to create an editor template just to display drop down values.
- The odd thing is that TextBoxFor will show the correct value. This seems to be an issue just with the drop down list.
How do I fix the binding so that the second drop down works? I debugged it. It would appear that ViewData.Eval is not picking up the correct value from _.Children[i].ChooseId
.
Update (bug)
This is a confirmed bug (low priority, how?) in the MVC framework http://aspnet.codeplex.com/workitem/8311
@using (Html.BeginForm())
{
for (int i = 0; i < Model.Children.Count(); i++)
{
<p>A: @Html.EditorFor(_ => _.Children[i], "ChildItem")</p>
<p>B: @Html.DropDownListFor(_ => _.Children[i].ChooseId, TestModel.PeopleSelect)</p>
}
<button type="submit">GO</button>
}
I have tried using DropDownListFor(_ => Model.Children[i].ChooseId)
, same result.
using TextBoxFor(_ => _.Children[i].ChooseId)
shows the correct value, wierd?
For reference here is ChildItem.cshtml
@using dropdown.Controllers
@using dropdown.Models
@model dropdown.Models.TestPerson
@Html.DropDownListFor(_ => _.ChooseId, TestModel.PeopleSelect)
It looks like this: