Reputation: 35
I have a quick question. I have a table named categories and i want to list as SelectListItem
. So far I tried with this code:
_context.Categories.ToList();
_context.Categories.AsIEnumerable();
but no luck.
How do I query my table as IEnumerable
?
Upvotes: 0
Views: 466
Reputation: 43929
Try this code:
var selectListItems= _context.Categories
.Select(i=> new SelectListItem {
Value=i.Id.ToString(),
Text=i.Name
}).ToList(); // or .ToArray() it will be a little more sufficient As enumerable
Upvotes: 1