title: How to get enum from model into view with displayfor
body: <p>I have trouble getting a view populated by a enum value from a model correctly.</p>
  
  <p>I tried reading up from this thread to help me out with a htmlhelper, with no prevail:
  <a href="https://stackoverflow.com/questions/15730907/how-find-the-enum-name-for-corresponding-value-and-use-it-in-displayfor">How find the enum name for corresponding value and use it in DisplayFor?</a></p>
  
  <pre><code>public static class HtmlExtensions
  {
      public static IHtmlString DisplayEnumFor&lt;TModel&gt;(this HtmlHelper&lt;TModel&gt; html, Expression&lt;Func&lt;TModel, int&gt;&gt; ex, Type enumType)
      {
          var value = (int)ModelMetadata.FromLambdaExpression(ex, html.ViewData).Model;
          string enumValue = Enum.GetName(enumType, value);
          return new HtmlString(html.Encode(enumValue));
      }
  }
  </code></pre>
  
  <p>But alas, it doesn't work. And I get this message:</p>
  
  <pre><code>CS0266: Cannot implicitly convert type 'HiltiHaninge.Models.Discplines' to 'int'. An explicit conversion exists (are you missing a cast?)
  </code></pre>
  
  <p>I've tried with my best effort not to make it to a int, but a string representation of that value that the model contains. The view:</p>
  
  <pre><code>@model HiltiHaninge.Models.CellEntity
  @using HiltiHaninge.Helpers
  
  @{
  ViewBag.Title = "Ta bort pass " + @Html.DisplayFor(model =&gt; model.Id) + ", på " + @Html.DisplayFor(model =&gt; model.Day);
  }
  
  &lt;h2&gt;@ViewBag.Title&lt;/h2&gt;
  
  &lt;h3&gt;Är du säker på att du vill radera inlägget?&lt;/h3&gt;
  &lt;fieldset&gt;
  &lt;legend&gt;Pass @Html.DisplayFor(model =&gt; model.Id)&lt;/legend&gt;
  
  &lt;div class="display-label"&gt;
      &lt;p class="text_without_indent"&gt;Tid från: (TT-MM)&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="display-field"&gt;
      @Html.DisplayFor(model =&gt; model.TimeFromHour)
      @Html.DisplayFor(model =&gt; model.TimeFromMinute)
  &lt;/div&gt;
  
  &lt;div class="display-label"&gt;
      &lt;p class="text_without_indent"&gt;Tid till: (TT-MM)&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="display-field"&gt;
      @Html.DisplayFor(model =&gt; model.TimeToHour)
      @Html.DisplayFor(model =&gt; model.TimeToMinute)
  &lt;/div&gt;
  
  &lt;div class="display-label"&gt;
       &lt;p class="text_without_indent"&gt;@Html.DisplayNameFor(model =&gt; model.Discipline)&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="display-field"&gt;
      @Html.DisplayEnumFor(model =&gt; model.Discipline, typeof(HiltiHaninge.Models.Discplines))
  &lt;/div&gt;
  
  &lt;div class="display-label"&gt;
       &lt;p class="text_without_indent"&gt;@Html.DisplayNameFor(model =&gt; model.Level)&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="display-field"&gt;
      @Html.DisplayEnumFor(model =&gt; model.Level, typeof(HiltiHaninge.Models.Levels))
  &lt;/div&gt;
  
  &lt;div class="display-label"&gt;
      &lt;p class="text_without_indent"&gt;@Html.DisplayNameFor(model =&gt; model.Coach)&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="display-field"&gt;
      @Html.DisplayFor(model =&gt; model.Coach)
  &lt;/div&gt;
  
  &lt;/fieldset&gt;
  @using (Html.BeginForm()) {
  @Html.AntiForgeryToken()
  &lt;p&gt;
      &lt;input type="submit" value="Ta bort" /&gt; |
      @Html.ActionLink("Tillbaka till listan", "Index")
  &lt;/p&gt;
  }
  </code></pre>
  
  <p>Anyone got any ideas, I'd appreciate it.</p>