1

How do I get a DropDownListFor helper to properly display all of the items of a model that a collection has?

@Html.DropDownListFor(model => model.Request.Leave_ID, new SelectList(Model.Leaves))

I tried modifying this part of code in many different ways but I'm not too good with Linq so I either got something like System.Data.Entity.DynamicProxies... etc returned or something else that is weird.

Basically my model has a colleciont of a Leave model which contains a Name property so I would like to make it possible so that the dropdown list will display the names of all of the Leaves.

Nitin Joshi
  • 1,638
  • 1
  • 14
  • 17
ab1428x
  • 794
  • 2
  • 8
  • 20

1 Answers1

1

Add dataValueField and textValueField parameters to the constructor of the SelectList:

@Html.DropDownListFor(model => model.Request.Leave_ID, new SelectList(Model.Leaves, "Name", "Name")))
Håkan Fahlstedt
  • 2,040
  • 13
  • 17