将SelectList转换为List

本文关键字:List 转换 SelectList | 更新日期: 2023-09-27 18:03:32

如何将SelectList转换为List() ?

代码:

Session["Employers"] = new SelectList(employers.DistinctBy(i => i.empId), "EmpId", "EmpName");

将SelectList转换为List

只需在末尾添加一个ToList()

Session["Employers"] = new SelectList(employers.DistinctBy(i => i.empId), "EmpId", "EmpName").ToList();
相关文章: