我有这样的课。
public static SkillViewModel GetAllList(string ID)
{
ListViewModel viewModel = new ListViewModel();
DataTable dt = DAL.GetAllList(ID);
List<Skill> skills = new List<Skill>();
foreach (DataRow row in dt.Rows)
{
Skill skill = new Skill() { GroupName = row["GroupName"] != null ? row["GroupName"].ToString() : string.Empty, SubName = row["SubName"] != null ? row["SubName"].ToString() : string.Empty};
skills.Add(skill);
}
viewModel.skills = skills;
viewModel.skills = skills.GroupBy(x => x.GroupName); //Showing error in this line
return viewModel;
}
还有一个是这样的:
public class SkillViewModel
{
public List<Skill> skills { get; set; }
}
public class Skill
{
[DisplayName("Sub Name")]
[Required]
public string SubName { get; set; }
[DisplayName("Group Name")]
[Required]
public string GroupName { get; set; }
}
但它通过说失败了
错误:无法将类型“System.Collections.Generic.IEnumerable>”隐式转换为“System.Collections.Generic.List”。存在显式转换(您是否缺少演员表?)
请帮忙。提前致谢。