gpt4 book ai didi

c# - Orderby Ascending on a list 错误asp.net

转载 作者:太空宇宙 更新时间:2023-11-03 23:03:56 24 4
gpt4 key购买 nike

<分区>

大家好,我正在构建一个允许用户提交帖子的应用程序,我正尝试在列表中按升序使用 orderby,但出现此错误

错误

The model item passed into the dictionary is of type 'System.Linq.OrderedEnumerable'2[myproject.Models.NewsPostVM,System.Nullable'1[System.Int32]]', but this dictionary requires a model item of type 'System.Collections.Generic.List'1[myproject.Models.NewsPostVM]'. Controller

public ActionResult News()
{
var posts = db.NewsPosts.Select(d => new NewsPostVM()
{
ID = d.ID,
Heading = d.Heading,
Body = d.Body,
Images = d.Images.Select(i => new NewsImageVM()
{
Path = i.Path,
FileName = i.DisplayName
}).ToList()
}).ToList();
var post= posts.OrderBy(m => m.ID);
return View(post);
}

查看

@model List<MyProject.Models.NewsPostVM>
@foreach (var p in Model)
{
<div class="w3-container w3-center">
<h5><b>@p.Heading</b></h5>
<p>@p.Body</p>
@foreach (var image in p.Images)
{
<img class="img-thumbnail" width="150" height="150" src="~/Images/@image.Path" />
}
<h6>@p.Date</h6>
</div>
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com