mardi 13 septembre 2016

how to get the value from Enum in HtmlHelper.dropdown mvc?

I write an Enum for months of year that my enum use resourse type for multi language

public enum MonthType : byte
    {
        [Display(ResourceType = typeof(Global.Caption), Name = "FirstMonth")]
        FirstMonth = 1,
        [Display(ResourceType = typeof(Global.Caption), Name = "SecoundMonth")]
        SecoundMonth = 2,
        [Display(ResourceType = typeof(Global.Caption), Name = "ThirdMonth")]
        ThirdMonth = 3,
        [Display(ResourceType = typeof(Global.Caption), Name = "ForthMonth")]
        ForthMonth = 4,
        [Display(ResourceType = typeof(Global.Caption), Name = "FifthMonth")]
        FifthMonth = 5,
        [Display(ResourceType = typeof(Global.Caption), Name = "SixthMonth")]
        SixthMonth = 6,
        [Display(ResourceType = typeof(Global.Caption), Name = "SeventhMonth")]
        SeventhMonth = 7,
        [Display(ResourceType = typeof(Global.Caption), Name = "EighthMonth")]
        EighthMonth = 8,
        [Display(ResourceType = typeof(Global.Caption), Name = "NinthMonth")]
        NinthMonth = 9,
        [Display(ResourceType = typeof(Global.Caption), Name = "TenthMonth")]
        TenthMonth = 10,
        [Display(ResourceType = typeof(Global.Caption), Name = "EleventhMonth")]
        EleventhMonth = 11,
        [Display(ResourceType = typeof(Global.Caption), Name = "TwelfthMonth")]
        TwelfthMonth = 12
    }

and i Used in my HtmlHelper.dropDownlist:

<div class="form-group">
                @Html.LabelFor(model => model.YearOfBirth, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownListFor(model => model.MonthOfBirth, new SelectList(Enum.GetValues(typeof(Shared.Entities.SMP.Enum.MonthType)))           )
                    @Html.ValidationMessageFor(model => model.YearOfBirth, "", new { @class = "text-danger" })
                </div>
            </div>

in RunTime i see just Enum's List with Resourse Type

Aucun commentaire:

Enregistrer un commentaire