c# GroupBy分组 去重

时间:2021-11-01 15:11:32

/// <summary>
/// 根据 RoleID And SectionStr 获取 UserInfoList
/// </summary>
/// <returns></returns>
public ActionResult GetUserDataByRoleAndSection(UserInfoViewModel viewModel)
{

IList<UserInfo> userinfolist = _service.GetUserByRoleAndSection(viewModel);

var userListvalue = userinfolist.GroupBy(p => new { p.ID, p.TrueName }).Select(g => g.First()).ToList();

if (userinfolist != null)
{
return Json(new { flag = "success", userinfolist = userListvalue });
}

return Json(new { flag = "error" });

}