【发布时间】:2013-04-15 15:54:50
【问题描述】:
我有这样的课程。
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”。一个 存在显式转换(您是否缺少演员表?)
请帮忙。提前致谢。
【问题讨论】:
标签: c# asp.net-mvc-2 casting