I'm facing a problem. I need to display a set of checkboxes with values coming from a Viewbag in my controller. Below is what I already have:
In the controller :
ViewBag.disciplines = new SelectList(db.Disciplines, "IdDiscipline", "IntituleDiscipline");
And in my view :
<div class="form-group" id="checkboxes">
<label class="control-label col-md-2" for="discipline"> Discipline : </label>
<div class="col-md-10">
@foreach (var item in ViewBag.disciplines)
{
<input type="checkbox"
value="@ViewBag.disciplines.IntituleDiscipline"
name="@ViewBag.disciplines.IntituleDiscipline"
id="@ViewBag.disciplines.IdDiscipline">
}
</div>
</div>
I wish to be able to display checkboxes with values as "IntituleDiscipline" and with ids as "IdDiscipline" (these id's come from the database).
When I execute this, I get an exception as such :
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''System.Web.Mvc.SelectList' does not contain a definition for 'IntituleDiscipline''.
What can I do to achieve the result please?