Convert List To IEnumerable


Answer :

Maybe try this? (untested)



ViewBag.AvaiableEnums = dynamicTextEnumsAvaiable.Select(x => 
new SelectListItem()
{
Text = x.ToString()
});


You could do the following



ViewBag.AvaiableEnums = new SelectList(dynamicTextEnumsAvaiable)


See http://msdn.microsoft.com/en-us/library/system.web.mvc.selectlist(v=vs.118).aspx



You can maybe use a Linq statement to convert it



IEnumerable<SelectListItem> myCollection = dynamicTextEnumsAvaiable
.Select(i => new SelectListItem()
{
Text = i.ToString(),
Value = i
});


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable