Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When I have a list of values that wont change I usualy use an Enum and then use a custom Html Helper to render out a select list. You can customzie the display text of the enum values by using meta data description markup.</p> <p>That way you can just use:</p> <pre><code> &lt;%: Html.EnumDropDownListFor(model =&gt; model.EnuProperty) %&gt; </code></pre> <p>or</p> <pre><code> @Html.EnumDropDownListFor(model =&gt; model.EnuProperty) </code></pre> <p>Check out this post by Simon which allows you to use the Meta Description attribute to customzie the output for Enum names:</p> <p><a href="https://stackoverflow.com/questions/388483/how-do-you-create-a-dropdownlist-from-an-enum-in-asp-net-mvc">How do you create a dropdownlist from an enum in ASP.NET MVC?</a></p> <p>Here is another example but it lacks the meta description property:</p> <p><a href="http://blogs.msdn.com/b/stuartleeks/archive/2010/05/21/asp-net-mvc-creating-a-dropdownlist-helper-for-enums.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/b/stuartleeks/archive/2010/05/21/asp-net-mvc-creating-a-dropdownlist-helper-for-enums.aspx</a></p> <p><strong>EDIT</strong></p> <p>Your enum might look something like this</p> <pre><code> public enum ChargeGroupEnum { [Description("Administration")] Administration=1, [Description("Annual Leave")] AnnualLeave=2, [Description("Bereavement")] Bereavement=3, [Description("Customer Installation, Setup &amp; Training")] CustomerInstallation=4, [Description("Customer Support")] CustomerSupport=5, [Description("Internal Training &amp; Education")] InternalTraining=6, [Description("Sales &amp; Marketing")] SalesMarketing=7, [Description("Sick")] Sick=8, [Description("Software Devel / Maint / Test")] Development=9, [Description("Software Upgrade / Patch")] Upgrade=10, [Description("Other")] Other=11, [Description("Other Absence")] OtherAbsence=12, [Description("Warranty")] Warranty=13, [Description("Public Holiday")] PublicHoliday=14, [Description(")ther Paid Leave")] OtherPaidLeave=15 } </code></pre> <p>And then on your View Model you could use the following to make the field start with no value and REQUIRE a value:</p> <pre><code> [Required(ErrorMessage=" * required")] public ChargeGroupEnum? ChargeGroup {get;set;} </code></pre> <p>And then in your view you would use the Html Helper "ChargeGroupEnum" which you'll need to get from the post I linked to.</p> <pre><code> @Html.EnumDropDownListFor(model =&gt; Model.ChargeGroup) </code></pre> <p>If your model has an Int, you can easly go from Enum => Int and Int => Enum with casting.</p>
    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. 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