我需要为通知列表创建一个分页系统,从本质上讲,它应该按月拆分通知列表。这是我的通知视图模型:
public class IndexViewModel
{
public string Template { get; set; }
public DateTime Created { get; set; }
}
这是相应的视图:
@model IEnumerable<IndexViewModel>
@{
ViewBag.Title = "List";
Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
var now = DateTime.Now;
}
<link href="@Url.Content("~/Resources/styles/Notifications/NotificationsPage.css")" rel="stylesheet" />
@foreach (IndexViewModel item in Model)
{
<div>
@Html.Raw(item.Template)
</div>
}
我需要一个非常简单的解决方案。任何想法都非常感谢。
这是返回我的视图模型的服务方法
public List<IndexViewModel> GetIndexViewModel(int? month, int? year )//(DateTime? entryDate)
{
//List<string> templates = GetRenderTemplates(true);
//Tuple<template, Created, ImportanceId>
List<Tuple<string, DateTime, int>> templates = GetTemplatesWithDateAndImportance(true);
templates = templates.OrderBy(f => f.Item3).ThenByDescending(f => f.Item2).Select(f => f).ToList();
if (month != null && year != null)
templates = templates.Where(f => f.Item2.Month == month && f.Item2.Year == year).ToList();
List<IndexViewModel> toRet = new List<IndexViewModel>();
foreach (Tuple<string, DateTime, int> template in templates)
{
toRet.Add(new IndexViewModel() {
Template = template.Item1,
Created = template.Item2
});
}
return toRet;
}
这是我的行动:
[ActionName("List")]
public ActionResult UsersList(int? month, int? year)
{
List<IndexViewModel> responseModel = Service.GetIndexViewModel(month, year);
return View(responseModel);
}