I have the following sample model:
public class FooModel
{
public List<Bar> myList { get; set; }
}
public class Bar
{
public string description { get; set; }
public int pos { get; set; }
public int myField { get; set; }
}
And, in my cshtml file I have this:
@foreach (var bar in Model.myList)
{
<div class="row">
<div class="col-2">PLACEHOLDER</div>
</div>
...
}
So basically, the field myField will be a match (when it has some value set) to a pos of another item. What I want, is to autogenerate a dropdown in PLACEHOLDER containing all the descriptions (and pos as value), of all Bar, with the one that matches selected.
I tried this approach (sample) but this shouldn't work, since I am in a foreach inside my Model
@Html.DropDownListFor(col=> col.myField, new SelectList(Model.myList.description, "Id", "Text"), "Choose... ")
Can I do this automatically or will I have to create the dropdown manually?
Thanks!