如何在我的主页上渲染出两个分页列表?
我愿意做它所需要的 - 如果它意味着定制我的代码以适应解决方案或定制现有解决方案以适合我的代码。
我已使用局部视图成功将一个分页列表呈现到主页。
看看我的代码: 查看 ..家> 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>
浏览 ..分享&gt; 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>
}
}
控制器&gt; 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);
}
模型&gt; 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&gt; 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();
}
}
}
答案 0 :(得分:0)
我想出来了!这是一个相当野蛮的任务...我花了将近10个小时试图解决这个问题所以请继续关注,因为我会给他们这样的答案。现在,我所要做的就是阻止刷新将我发送回页面顶部。哎呀!希望不会那么糟糕......(: