[英]How to IEnumerable query in ASP.NET Core MVC?
我有一个快速的问题。 我有一个名为 categories 的表,我想列为SelectListItem
。 到目前为止,我尝试使用此代码:
_context.Categories.ToList();
_context.Categories.AsIEnumerable();
但没有运气。
如何将我的表查询为IEnumerable
?
试试这个代码:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.