Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok So i think there must be a problem with the RadioBoxForEnum code, as I found a different way of doing this and created an editor template using the following code I found and this works with any issues.</p> <p>Enum_radioButtonList.cshtml</p> <pre><code>@model Enum @{ // Looks for a [Display(Name="Some Name")] or a [Display(Name="Some Name", ResourceType=typeof(ResourceFile)] Attribute on your enum Func&lt;Enum, string&gt; getDescription = en =&gt; { Type type = en.GetType(); System.Reflection.MemberInfo[] memInfo = type.GetMember(en.ToString()); if (memInfo != null &amp;&amp; memInfo.Length &gt; 0) { object[] attrs = memInfo[0].GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.DisplayAttribute), false); if (attrs != null &amp;&amp; attrs.Length &gt; 0) return ((System.ComponentModel.DataAnnotations.DisplayAttribute)attrs[0]).GetName(); } return en.ToString(); }; var listItems = Enum.GetValues(Model.GetType()).OfType&lt;Enum&gt;().Select(e =&gt; new SelectListItem() { Text = getDescription(e), Value = e.ToString(), Selected = e.Equals(Model) }); string prefix = ViewData.TemplateInfo.HtmlFieldPrefix; int index = 0; ViewData.TemplateInfo.HtmlFieldPrefix = string.Empty; foreach (var li in listItems) { string fieldName = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}_{1}", prefix, index++); &lt;div class="editor-radio"&gt; @Html.RadioButton(prefix, li.Value, li.Selected, new { @id = fieldName }) @Html.Label(fieldName, li.Text) &lt;/div&gt; } ViewData.TemplateInfo.HtmlFieldPrefix = prefix; } </code></pre> <p>And this gets called as follows:</p> <pre><code>@Html.EditorFor(o =&gt; o.ChangeProposalHeader.ChangeProposal.FitType, "Enum_radioButtonList") </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload