gpt4 book ai didi

c# - 在 Razor View 中将 linq 与动态模型结合使用

转载 作者:太空宇宙 更新时间:2023-11-03 21:12:32 26 4
gpt4 key购买 nike

在 mvc 页面上使用动态模型并尝试使用 linq 在 for each 循环中“跳过”和“获取”。

但是,每次我这样做时,我都会得到这个错误: enter image description here

我的代码是这样的:

@model dynamic
@foreach (var article in Model.Articles.Take(2))
{
<div class="col-md-4">
<a href='@Url.Action("Details", "Content", new { Id = article.Id }, null)'>
<img class="img img-responsive" src="@(article.ImageUrl)" />
</a>
@article.Title
</div>
}

谢谢

最佳答案

由于 Take 是一种扩展方法,因此您需要包含命名空间 using System.Linq

在 mvc razor 中,它将是 @using System.Linq

关于c# - 在 Razor View 中将 linq 与动态模型结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36730004/

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