title: Radio button group from enum
body: <p>I'm trying to come up with a generic view model and editor template for enum types in a way that possible values are rendered into a radio button group. Let me elaborate.</p>
  
  <p>The VM looks like so</p>
  
  <pre><code>public class OptionViewModel&lt;TEnum&gt; where TEnum : struct, IConvertible
  {
     public TEnum SelectedValue { get; set; }
  }
  </code></pre>
  
  <p>I could then create an instance for any enum in my project by writing</p>
  
  <pre><code>public enum Numbers { One, Two, Three }
  
  ...
  NumberOptions = new OptionViewModel&lt;Numbers&gt;();
  ...
  </code></pre>
  
  <p>and then have that rendered via</p>
  
  <pre><code>@model OptionViewModel&lt;TEnum&gt;
  
  @foreach (var value in Enum.GetValues(typeof(TEnum)).Cast&lt;TEnum&gt;())
  {
     var selected = value == Model.SelectedValue;
  
     @Html.RadioButton(value.ToString(), value, selected)
  }
  </code></pre>
  
  <p>Unfortunately, the template doesn't even compile, because there is no type 'TEnum', of course.</p>
  
  <p>Is there a better (working) way to do this? I'd really get this level of abstraction, as radio button groups from enums is a fairly common case in my project, and it comes with additional attributes, such as IsVisible, IsEnabled and the like.</p>