I have tried a lot of things but I can't figure out how to do it. I'm getting a List of objects from my database and I actually want to display all the objects in a view. So i get my list of objects thanks to that function:
List<Contact> ListeContacts = StructureData.DonneListeContact(NumDossier);
Then I pass my list to the ViewBag :
ViewBag.ListeContacts = ListeContacts;
So now I would like to display all the properties of each object in a select in the view, so I tried that way:
<select>
@foreach (System.Data.DataRow Contact in ViewBag.ListeContact)
{
<option>@Html.DisplayName(Contact["nom_contact"].ToString())</option>
}
</select>
But it shows me a "NullReferenceExeption" on the foreach. There are a lot of examples on the net but all are done with EntityFramework so it's simple when using a model data structure. Does somebody has an idea ?