Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thank you all for your contributions<br/> Yngvebn, i tried your solution (in your last comment) before, but the only thing i didn't do is the <code>&lt;dynamic&gt;</code>, i used instead <code>&lt;Enum&gt;</code> in generic type.</p> <p>at last the solution is :<br/> create a template named Enum.acsx and put it under the <strong>Views\Shared\EditorTemplates </strong><br/></p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;dynamic&gt;" %&gt; &lt;%@ Import Namespace="System.Web.Mvc.Html" %&gt; &lt;%@ Import Namespace="the extension methods namespace" %&gt; &lt;% Enum model = (Enum)Model; %&gt; &lt;%=Html.DropDownList(model.GetType().Name,model.GetType())%&gt; </code></pre> <p>and in your Entity:</p> <pre><code>public class Person { [UIHint("Enum")] public GenderEnum Gender{get;set;} } public Enum GenderEnum { [Description("Male Person")] Male, [Description("Female Person")] Female } </code></pre> <p>and again there is Extention Methods:</p> <pre><code>public static class HtmlHelperExtension { public static MvcHtmlString DropDownListFor&lt;TModel, TProperty&gt;(this HtmlHelper&lt;TModel&gt; htmlHelper, Expression&lt;Func&lt;TModel, TProperty&gt;&gt; expression, Type enumType) { List&lt;SelectListItem&gt; list = new List&lt;SelectListItem&gt;(); Dictionary&lt;string, string&gt; enumItems = enumType.GetDescription(); foreach (KeyValuePair&lt;string, string&gt; pair in enumItems) list.Add(new SelectListItem() { Value = pair.Key, Text = pair.Value }); return htmlHelper.DropDownListFor(expression, list); } /// &lt;summary&gt; /// return the items of enum paired with its descrtioption. /// &lt;/summary&gt; /// &lt;param name="enumeration"&gt;enumeration type to be processed.&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public static Dictionary&lt;string, string&gt; GetDescription(this Type enumeration) { if (!enumeration.IsEnum) { throw new ArgumentException("passed type must be of Enum type", "enumerationValue"); } Dictionary&lt;string, string&gt; descriptions = new Dictionary&lt;string, string&gt;(); var members = enumeration.GetMembers().Where(m =&gt; m.MemberType == MemberTypes.Field); foreach (MemberInfo member in members) { var attrs = member.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attrs.Count() != 0) descriptions.Add(member.Name, ((DescriptionAttribute)attrs[0]).Description); } return descriptions; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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