1

我正在处理一个显示对象列表的网页,但它们以完全随机且混乱的方式显示。我试图让它们按字母顺序显示。

我到目前为止的代码是:

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 错误)。

4

0 回答 0