【发布时间】:2015-09-06 01:12:37
【问题描述】:
我正在使用 PagedList.Mvc 并且当我制作 Filter Like localhost:2241/Samsung 并转到第 2 页 浏览器重定向到 localhost:2241/ 而不是 本地主机:2241/三星/Page2
我该如何解决这个问题
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<OnlineShoppingStore.WebUI.Models.ProductListViewModel>但仍然无法正常工作..请写一个不解释的代码..我很感激..谢谢
标签: c# asp.net asp.net-mvc asp.net-mvc-5 pagedlist