title: Cannot convert type 'TEnum' to 'int'
body: <p>I'm trying to convert an enum to a List as mentioned in <a href="https://stackoverflow.com/questions/3489453/how-can-i-convert-an-enumeration-into-a-listselectlistitem">this</a> example
  e.g.</p>
  <pre><code>Enum.GetValues(typeof(MyEnum)).Cast&lt;MyEnum&gt;().Select(v =&gt; new SelectListItem {
      Text = v.ToString(),
      Value = ((int)v).ToString()
  }).ToList();
  </code></pre>
  <p>This work but I want to amend it to work with a generic enum</p>
  <pre><code>public static List&lt;SelectListItem&gt; GetEnumList&lt;TEnum&gt;(TEnum value)
  {
  
          return Enum.GetValues(typeof(TEnum)).Cast&lt;TEnum&gt;().Select(v =&gt; new SelectListItem
          {
              Text = v.ToString(),
              Value = ((int)v).ToString()
          }).ToList();
   }
  </code></pre>
  <p>However the above code doesn't compile and gives</p>
  <blockquote>
  <p>Cannot convert type 'TEnum' to 'int'</p>
  </blockquote>
  <p>for the line</p>
  <pre><code>  Value = ((int)v).ToString()
  </code></pre>
  <ol>
  <li><p>How do I fix this above code.</p>
  </li>
  <li><p>Why is it giving a compile error with generic enum and not with a normal enum</p>
  </li>
  </ol>
  <hr />
  <p>Edit: I have tried the suggestions in the thread but I get a further error:</p>
  <p>Here is my full code:</p>
  <pre><code>public static IHtmlContent EnumDropDownListFor&lt;TModel, TResult,TEnum&gt;(
      this IHtmlHelper&lt;TModel&gt; htmlHelper,
      Expression&lt;Func&lt;TModel, TResult&gt;&gt; expression,
      TEnum enumValue,
      string optionLabel) 
  {
      return htmlHelper.DropDownListFor(expression, (IEnumerable&lt;SelectListItem&gt;)GetEnumList(enumValue), optionLabel);
  }
  
  public static List&lt;SelectListItem&gt; GetEnumList&lt;TEnum&gt;(TEnum value) 
  {
      return Enum.GetValues(typeof(TEnum)).Cast&lt;TEnum&gt;().Select(v =&gt; new SelectListItem
      {
          Text = v.ToString(),
          Value = Convert.ToInt32(v).ToString()
      }).ToList();
  
  }
  </code></pre>
  <p>but I get a runtime error</p>
  <blockquote>
  <p>ArgumentException: Type provided must be an Enum.</p>
  <p>Parameter name: enumType</p>
  </blockquote>
  <p>on the line</p>
  <pre><code>return Enum.GetValues(typeof(TEnum)).Cast&lt;TEnum&gt;().Select(v =&gt; new SelectListItem
      {
          Text = v.ToString(),
          Value = Convert.ToInt32(v).ToString()
      }).ToList();
  </code></pre>
  <p>What do I need to fix in the code to not get the runtime error.</p>