enumdropdownlistfor

how to use enum with DescriptionAttribute in asp.net mvc

女生的网名这么多〃 提交于 2019-12-04 10:21:05
问题 I am new to asp.net MVC. I am trying to use dropdown control on my view page, which populates from enum. I also want to add custom descriptions to dropdown values. I searched so many examples, but no one posted how to populated description on view page. Here is my code: ViewModel: public enum SearchBy { [Description("SID/PID")] SID = 1, [Description("Name")] Name, [Description("Birth Date")] DOB, [Description("Cause#")] Cause } Index.cshtml <div class="form-horizontal"> @Html

how to use enum with DescriptionAttribute in asp.net mvc

廉价感情. 提交于 2019-12-03 05:26:51
I am new to asp.net MVC. I am trying to use dropdown control on my view page, which populates from enum. I also want to add custom descriptions to dropdown values. I searched so many examples, but no one posted how to populated description on view page. Here is my code: ViewModel: public enum SearchBy { [Description("SID/PID")] SID = 1, [Description("Name")] Name, [Description("Birth Date")] DOB, [Description("Cause#")] Cause } Index.cshtml <div class="form-horizontal"> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group form-inline"> @Html.LabelFor(model =