I am using asp.net mvc. This might be a straight forward one. I am binding my drop-down list to an enum as follows
@Html.DropDownListFor(m => m.IndicatorGroups, Model.IndicatorGroups.ToSelectList(), new { @id = "ddlIndicatorGroup" })
Model is defined as follows
public class SearchControlViewModel
{
...
public GlobalEnums.IndicatorGroup IndicatorGroups { get; set; }
...
}
ToSelectList function is defined as follows
public static SelectList ToSelectList<TEnum>(this TEnum enumObj) where TEnum : struct, IComparable, IFormattable, IConvertible
{
var values = from TEnum e in Enum.GetValues(typeof(TEnum))
select new { Id = Convert.ToInt32(e), Name = e.ToString() };
return new SelectList(values, "Id", "Name", enumObj);
}
Now i have added values with spaces to enum and i want to display these values instead of "values with underscores"
public enum IndicatorGroup
{
[EnumMember(Value = "Include ANY MatchingIndicator")]
Include_ANY_MatchingIndicator = 1,
[EnumMember(Value = "Include ALL MatchingIndicator")]
Include_ALL_MatchingIndicator,
[EnumMember(Value = "Exclude ANY MatchingIndicator")]
Exclude_ANY_MatchingIndicator,
[EnumMember(Value = "Exclude ALL MatchingIndicator")]
Exclude_ALL_MatchingIndicator
};
How can i accomplish this?