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
?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.