scottdavidwalker
scottdavidwalker

Reputation: 1541

Using linq with dynamic model in Razor View

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: enter image description here

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

Answers (1)

cableload
cableload

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

Related Questions