-1
我使用PagedList.Mvc,当我做过滤像 本地主机丢失:2241 /三星并转到第2页 的浏览器重定向到本地主机:/ 2241,而不是本地主机 :2241 /三星/第2页PagedList.Mvc分页时我过滤产品
我怎样才能解决这个
ProductController.cs
public class ProductController : Controller
{
private readonly IProductRepository repository;
public ProductController(IProductRepository repo)
{
repository = repo;
}
public ViewResult List(int? page, string category)
{
ProductListViewModel model = new ProductListViewModel
{
Prodcuts = repository.Products
.Where(p => category == null || p.Category == category),
CurrentCategory = category
};
return View (model.Prodcuts.ToList().ToPagedList(page ?? 1, 3));
}
}
List.cshtml
@model IPagedList<OnlineShoppingStore.Domain.Entities.Product>
@using PagedList;
@using PagedList.Mvc;
....
@foreach (var p in Model)
{
@Html.Partial("ProductSummary",p)
}
@Html.PagedListPager(Model, page => Url.Action("List", new {page }))
ProductListViewModel.cs
public class ProductListViewModel
{
public IEnumerable <Product> Prodcuts { get; set; }
public string CurrentCategory { get; set; }
}
我该怎么办?
我该怎么做? –
用完整的代码编辑的帖子..我不是专业的,仍然在学习MVC所以请告诉我在哪里我可以编辑或添加代码..我做了你之前说'category = Model.CurrentCategory' ..和'@model IPagedList'但仍然无法正常工作..请写一个代码不解释..我明白了..谢谢 –