title: Make a CheckBox list in Asp.net mvc4 - showing items from Database
body: <p>Hey This is my model that i joint 3 tables in it.</p>
  
  <pre><code>    public Student Student { get; set; }
      public Simester Semester { get; set; }
      public Lesson Lesson { get; set; }
  </code></pre>
  
  <p>And this is my Controller:</p>
  
  <pre><code> [HttpGet]
          public ActionResult UnitSelection()
          {
              var students = context.Students;
              ViewBag.Students = new SelectList(students, "Id", "FullName");
  
              var semesters = context.Simesters;
              ViewBag.Semesters = new SelectList(semesters, "Id", "Title");
  
              var lessons = context.Lessons;
              ViewBag.Lessons = new SelectList(lessons, "Id", "Title");
              return View();
          }
  
          [HttpPost]
          public ActionResult UnitSelection(UnitSelectionViewModel model)
          {
              StudnetLesson snl = new StudnetLesson();
              snl.LessonId = model.Lesson.Id;
              snl.StudentId = model.Student.Id;
              snl.SimesterId = model.Semester.Id;
              context.StudnetLessons.Add(snl);
              context.SaveChanges();
  
  
              return RedirectToAction("Success");
  
          }
  </code></pre>
  
  <p>I want to show a checkbox list in my view in foreach loop.
  I want to show Lessons in checkbox list(its string)</p>
  
  <pre><code>public Lesson Lesson { get; set; }
  </code></pre>
  
  <p>I tested many codes and It does not work any tips?</p>
  
  <pre><code>@using (Html.BeginForm("UnitSelection", "Home", FormMethod.Post))
          {
              &lt;text&gt;Student Name: &lt;/text&gt;
              @Html.DropDownListFor(x =&gt; x.Student.Id, (SelectList)ViewBag.Students, "Choose a student")
              &lt;br /&gt;
              &lt;text&gt;Semester: &lt;/text&gt;
              @Html.DropDownListFor(x =&gt; x.Semester.Id, (SelectList)ViewBag.Semesters, "Choose your semester")
              &lt;br /&gt;
              &lt;text&gt;Lesson: &lt;/text&gt;
              foreach (var lessons in (SelectList) ViewBag.Lessons)
              {
              }
  
          }
  </code></pre>