Skip to content

Instantly share code, notes, and snippets.

@mgroves
Created October 13, 2013 22:28
Show Gist options
  • Select an option

  • Save mgroves/6968090 to your computer and use it in GitHub Desktop.

Select an option

Save mgroves/6968090 to your computer and use it in GitHub Desktop.
<p>
<select name="Associations[0].SomeId">
<option value="">Select...</option>
<option value="7">AAA</option> <!-- why isn't a value in the dropdown selected? -->
<option value="8">BBB</option>
<option value="9">CCC</option>
</select>
<!-- but yet, the value here is populated -->
<input name="Associations[0].Foo" type="text" value="whatever">
</p>
<p>
<select name="Associations[1].SomeId">
<option value="">Select...</option>
<option value="7">AAA</option> <!-- why isn't a value in the dropdown selected? -->
<option value="8">BBB</option>
<option value="9">CCC</option>
</select>
<!-- but yet, the value here is populated -->
<input name="Associations[1].Foo" type="text" value="something else">
</p>
@model MyNamespace.SomeViewModel
@for (int i = 0; i < Model.Associations.Count; i++)
{
<p>
@* SomeId property has an interger value, like 7 *@
@Html.DropDownListFor(a => a.Associations[i].SomeId, Model.SomeList, "Select...")
@* Foo property has a string value, like "whatever" *@
@Html.TextBoxFor(a => a.Associations[i].Foo)
</p>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment