title: MVC display checkbox for weekday enum
body: <p>I have an enum:</p>
  
  <pre><code>[Flags]
  public enum DayOfWeekEnum
  {
      None = 0,
      Monday = 1,
      Tuesday = 2,
      Wednesday = 4,
      Thursday = 8,
      Friday = 16,
      All = 31
  }
  </code></pre>
  
  <p>And I want to display it in a asp.net mvc application in a form of a list of checkboxes. </p>
  
  <p>I found this code:</p>
  
  <pre><code>@foreach (DayOfWeekEnum item in Enum.GetValues(typeof(DayOfWeekEnum)))
          {
              if (item &gt; 0 &amp;&amp; item &lt;= DayOfWeekEnum.Friday)
              {
                  @Html.Label("DayOfWeekEnum", item.ToString())
                  @Html.CheckBox("DayOfWeekEnum", (Model.Availability.HasFlag(item)),
                      new {value = item})
  
              }
          }
  </code></pre>
  
  <p>However, it does not send the values back to the controller.</p>
  
  <p>Model looks like this:</p>
  
  <pre><code>public class Teacher
  {
      public int Id { get; set; }
      public User User { get; set; }
      public Level Level { get; set; }
      public DayOfWeekEnum Availability { get; set; }
  }
  </code></pre>
  
  <p>Controller looks like this:</p>
  
  <pre><code>    [HttpPost] 
      [ValidateAntiForgeryToken]
      public ActionResult Create([Bind(Include = "id,User,Level,Availability")] Teacher
          teacher)
      {
          if (ModelState.IsValid)
          {
              serviceClient.AddTeacher(teacher);
              return RedirectToAction("Index");
          }
  
          return View(teacher);
      }
  </code></pre>