显示最后3个项目的列表

时间:2018-02-14 13:25:48

标签: asp.net-mvc slider

我在我的视图中使用此代码作为滑块 但我想展示最后3个项目

    <div class="flexslider">
            <ul class="slides">
                @foreach (var item in ViewBag.blog)
                {
                    <li>
                        <a href="#">
                            <img src="@item.postImage" width="100%" alt="PostImage" style="margin-bottom: 10px;" />
                            <p class="flex-caption">@item.postTitle</p>
                        </a>
                    </li>
                }
            </ul>
        </div>

1 个答案:

答案 0 :(得分:1)

<div class="flexslider">
            <ul class="slides">
                @foreach (var item in ((List<your Model>)ViewBag.blog).Skip(((List<your Model>)ViewBag.list).Count-3))
                {
                    <li>
                        <a href="#">
                            <img src="@item.postImage" width="100%" alt="PostImage" style="margin-bottom: 10px;" />
                            <p class="flex-caption">@item.postTitle</p>
                        </a>
                    </li>
                }
            </ul>
        </div>