title: ASP.NET MVC - Problem with EditorTemplate for ICollection<T> mapped to Enum
body: <p>I have an ASP.NET MVC 3 (Razor) website, and a (simplified) model called <strong>Review</strong>:</p>
  
  <pre><code>public class Review
  {
     public int ReviewId { get; set; }
     public bool RecommendationOne
     {
         // hook property - gets/set values in the ICollection
     }
     public bool RecommendationTwo { // etc }
     public ICollection&lt;Recommendation&gt; Recommendations { get; set; }
  }
  </code></pre>
  
  <p><strong>Recommendation</strong>  is as follows:</p>
  
  <pre><code>public class Recommendation
  {
     public byte RecommendationTypeId
  }
  </code></pre>
  
  <p>I also have an <strong>enum</strong> called <strong>RecommendationType</strong>, which i use to map the above recommendation to. (based on RecommendationTypeId).</p>
  
  <p>So to summarize - a <strong>single Review</strong> has <strong>many Recommendations</strong>, and each of those Recommendations map to a particular enum type, i expose hook properties to simplify model-binding/code.</p>
  
  <p>So, onto the View:</p>
  
  <pre><code>@Html.EditorFor(model =&gt; model.Recommendations, "Recommendations")
  </code></pre>
  
  <p>Pretty simple.</p>
  
  <p>Now, for the editor template, i want to display a checkbox for each possible <strong>RecommendationType</strong> (enum), and if the model has that recommendation (e.g on edit view), i check the box.</p>
  
  <p>Here's what i have:</p>
  
  <pre><code>@model IEnumerable&lt;xxxx.DomainModel.Core.Posts.Recommendation&gt;
  @using xxxx.DomainModel.Core.Posts;
  
  @{
      Layout = null;
  }
  
  &lt;table&gt;
      @foreach (var rec in Enum.GetValues(typeof(RecommendationType)).Cast&lt;RecommendationType&gt;())
      {
          &lt;tr&gt;
              &lt;td&gt;
                  @* If review contains this recommendation, check the box *@
                  @if (Model != null &amp;&amp; Model.Any(x =&gt; x.RecommendationTypeId == (byte)rec))
                  {
                      @* How do i create a (checked) checkbox here? *@
                  }
                  else
                  {
                      @* How do i created a checkbox here? *@
                  }
  
                  @rec.ToDescription()
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  </code></pre>
  
  <p>As the comments suggest - i don't know how to use <code>@Html.CheckBoxFor</code>. Usually that takes an expression based on the model, but i'm how sure how to bind to the hook property based on the currently looped enum value. E.g it needs to dynamically do <code>@Html.CheckBoxFor(x =&gt; x.RecommendationOne)</code>, <code>@Html.CheckBoxFor(x =&gt; x.RecommendationTwo)</code>, etc.</p>
  
  <p><strong>The current solution i have</strong> (which works), involves manually constructing the <code>&lt;input&gt;</code> (including hidden fields).</p>
  
  <p>But as i'm just getting the hang of editor templates, hoping someone with experience can point me in a "strongly-typed" direction.</p>
  
  <p>Or is there a nicer way (HTML Helper) i can do this?</p>