Working with Enum values is very useful in so many circumstances and when you need to covert these enum values to List<SelectListItem>, here is how you can do it;
That is all- nice and simple!
public List<SelectListItem> GetPaymentOptions()
{
PaymentOptions[] values = (PaymentOptions[])Enum.GetValues(typeof(PaymentOptions));
var list = from value in values
select new SelectListItem()
{
Value = ((int)value).ToString(),
Text = value.ToString()
};
List<SelectListItem> paymentOptions = list.ToList<SelectListItem>();
return paymentOptions;
}
{
PaymentOptions[] values = (PaymentOptions[])Enum.GetValues(typeof(PaymentOptions));
var list = from value in values
select new SelectListItem()
{
Value = ((int)value).ToString(),
Text = value.ToString()
};
List<SelectListItem> paymentOptions = list.ToList<SelectListItem>();
return paymentOptions;
}
That is all- nice and simple!
Happy coding!
Comments
Post a Comment