Reputation: 1541
Using a dynamic model on an mvc page and attempting to use linq to "skip" and "take" in a for each loop.
However, every time I do it I get this error:
my code is this:
@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>
}
Thanks
Upvotes: 2
Views: 3663
Reputation: 4385
Since Take is an extension method, you need to include the namespace using System.Linq
In mvc razor, it would be @using System.Linq
Upvotes: 4