我在对传递给视图的用户配置文件列表进行排序时遇到问题。我想显示某个角色的所有用户的列表,并且我想按 familyName 属性对它们进行排序。
我尝试使用 OrderBy 但它没有效果。
控制器中的代码
public ActionResult Index()
{
//get all patients
var patients = Roles.GetUsersInRole("user").ToList();
//set up list of patient profiles
List<UserProfile> pprofiles = new List<UserProfile>();
foreach (var i in patients) {
pprofiles.Add(ZodiacPRO.Models.UserProfile.GetUserProfile(i));
}
pprofiles.OrderBy(x => x.familyName); //<-this has no effect the list produced is
// exactly the same it was without this line
return View(pprofiles);
}
和视图
<ul id= "patientList">
@foreach (var m in Model)
{
<li>
<ul class="patient">
<li class="ptitle">@m.title</li>
<li class="pname"> @Html.ActionLink(@m.givenName + " " + @m.familyName, "View", "Account", new { @username = @m.UserName.ToString() }, new { id = "try" })</li>
<li class="pprofile">@Ajax.ActionLink("Profile", "PatientSummary", new { @username = @m.UserName }, new AjaxOptions { UpdateTargetId = "pContent"},new{ @class = "profpic" })</li>
</ul>
</li>
}
</ul>
我需要在多个地方重复使用它,并且可能有大量用户,所以不以某种方式订购它们会很糟糕。我该怎么办?