我正在一个显示对象列表的网页上工作,但它们以完全随机和混乱的方式显示。我试图按字母顺序显示它们。
到目前为止,我的代码是:
public ActionResult Listing(string id)
{
List<MediaListingPreviewModel> models = null;
if (!string.IsNullOrEmpty(id))
{
var ids = id.Split(new char[] { ',', '&' }).Select(n => new Guid(n)).ToArray();
if (ids.Length > 0)
{
models = Mapper.Map<IEnumerable<MediaListingPreviewModel>>(RetrieveRepository<MediaSpace>().GetMany(n => ids.Contains(n.Id))).ToList();
}
}
else
{
models = Mapper.Map<IEnumerable<MediaListingPreviewModel>>(RetrieveRepository<MediaSpace>().GetMany(n => n.Deleted == false && n.Placements.Where(p => p.Deleted == false).Count() > 0)).ToList();
}
if (models.Count() < 5)
{
var currentCount = models.Count();
while (currentCount < 5)
{
var model = new MediaListingPreviewModel();
models.Add(model);
currentCount++;
}
}
return View(models.Take(models.Count).OrderBy(model => model.Name).ToArray());
}
我尝试过多次修改return语句,例如使用OrderByDescending(model => model)
但它不起作用(我在应该显示列表的页面上出现404错误)。< / p>