Tricky problem here. I\'m trying to convert items for a list to IEnumerable
.
dynamicTextInDatabase
si
If you need to convert a List of objects (without Enums) to IEnumerable, you can use a declarative style of LINQ:
var items = from TipoDoc t in tipoDocs
select new SelectListItem {Value = t.Id, Text = t.Description};
Here, tipoDocs is a List of objects of type TipoDoc
public class TipoDoc
{
public string Id { get; set; }
public string Description { get; set; }
}
have you tried
IEnumerable<SelectListItem> myCollection = dynamicTextEnumsAvaiable.AsEnumerable()
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
Just use .AsEnumerable() method.
Example:
IEnumerable<SelectListItem> myCollection = dynamicTextEnumsAvaiable.AsEnumerable()
Check out here: https://msdn.microsoft.com/en-us/library/system.data.datatableextensions.asenumerable(v=vs.110).aspx
You can maybe use a Linq statement to convert it
IEnumerable<SelectListItem> myCollection = dynamicTextEnumsAvaiable
.Select(i => new SelectListItem()
{
Text = i.ToString(),
Value = i
});