如何在我的主页上呈现两个分页列表?
我愿意做任何事情——如果这意味着定制我的代码以适合解决方案或定制现有解决方案以适合我的代码。
我已经使用部分视图成功地将一个分页列表呈现到主页。
看看我的代码: Views ..Home > Index.cshtml
@foreach (var m in Model.First)
{
Html.RenderPartial("FirstSummary", m);
}
<div class="pager">
@Html.PageLinks(Model.PagingInfo, x => Url.Action("Index", new { page = x }))
</div>
视图 ..Shared > FirstSummary.cshtml
@model MovinMyStuff.Domain.Entities.First
@{
if (@Model.IsActive)
{
<div class="first-list-item">
<ul>
<li>
<span class="first-name">
@Model.Property.ToString()
@Model.Property.ToString()
@Model.Property.ToString() -
@Model.Property.ToString()
@Model.Property.ToString()
@Model.Property.ToString()
</span>
</li>
<li>
@Html.ActionLink("Details", "Details", "First", new { area = "", id = @Model.FirstId }, new { @class = "button" })
</li>
</ul>
</div>
}
}
控制器 > HomeController.cs
public ViewResult Index(int page = 1)
{
FirstListViewModel viewModel = new FirstListViewModel
{
First = repository.First
.OrderByDescending(m => m.FirstId)
.Skip((page - 1) * PageSize)
.Take(PageSize),
PagingInfo = new PagingInfo
{
CurrentPage = page,
ItemsPerPage = PageSize,
TotalItems = repository.First.Count()
}
};
return View(viewModel);
}
模型 > FirstListViewModel.cs
using System.Collections.Generic;
using MovinMyStuff.Domain.Entities;
namespace MovinMyStuff.WebUI.Models
{
public class FirstListViewModel
{
public IEnumerable<First> Firsts { get; set; }
public PagingInfo PagingInfo { get; set; }
}
}
ViewModels > FirstAndSecond.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MovinMyStuff.WebUI.Models;
namespace MovinMyStuff.WebUI.ViewModels
namespace MovinMyStuff.WebUI.ViewModels
{
public class MovesAndMovers
{
public MovesListViewModel movesList { get; set; }
public MoversListViewModel moversList { get; set; }
public MovesAndMovers()
{
movesList = new MovesListViewModel();
moversList = new MoversListViewModel();
}
}
}