title: CheckBoxList for Enum types MVC Razor
body: <p>In my c#.net MVC application i would like to display checkbox list for Enum types.</p>
  
  <p>I have an enum type</p>
  
  <pre><code>[Flags]
  public enum ModeType
  {
  Undefined = 0,
  Read= 1,
  Edit= 2
    }
  </code></pre>
  
  <p>and my Model is </p>
  
  <pre><code>Public TrainingModel
     {
           public int UserID {get;set;}
           public ModeType Type {get;set}
     }
  </code></pre>
  
  <p>In my view i need two checkbox one for Read and the other for Edit
  So i tried </p>
  
  <pre><code>    @Html.CheckBoxFor(m =&gt; m.Type== ModeType.Read)
  @Html.CheckBoxFor(m =&gt; m.Type== ModeType.Edit)
  </code></pre>
  
  <p>But this give me error 
  "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions."</p>
  
  <p>I worked around this problem by adding two more properties to my model</p>
  
  <pre><code> Public TrainingModel
     {
           public int UserID {get;set;}
           public ModeType Type {get;set}
           public bool IsRead
           {
             get{Type.HasFlag(ModeType.Read);}
             set{Type |=ModeType.Read;}
           }
           public bool IsEdit
           {
             get{Type.HasFlag(ModeType.Edit);}
             set{Type |=ModeType.Edit;}
           }
  
     }
  </code></pre>
  
  <p>and then making my view</p>
  
  <pre><code>@Html.CheckboxFor(m =&gt; m.IsRead)
  @Html.CheckboxFor(m =&gt; m.IsEdit)
  </code></pre>
  
  <p>I know that the way i have approached it is not correct and there should be a better way to achieve this.
  Could someone please advise me on this.</p>