发布后,来自(sakura.AspNetCore)的寻呼机按钮会生成错误的网址,错过了网站的基本文件夹。例如,在此视图中:http://localhost/glide/Clientes点击寻呼机按钮“2”后,生成的网址为:http://localhost/Clientes?page=2导致HTTP 404.0 - 未找到,因为缺少“/ glide”。
Startup.cs
app.UseMvc(routes => {
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
ClientesController.cs
public async Task<IActionResult> Index(string searchString, string sortOrder, int? page)
{
ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
var clientes = from c in _context.ClienteBasico
select c;
if (!String.IsNullOrEmpty(searchString))
{
clientes = clientes.Where(c => c.Nome.Contains(searchString));
}
var pageNumber = (page ?? 1);
var pageSize = 5;
switch (sortOrder)
{
case "name_desc":
clientes = clientes.OrderByDescending(c => c.Nome);
break;
default:
clientes = clientes.OrderBy(c => c.Nome);
break;
}
//return View(clientes.ToList());
return View(clientes.ToPagedList(pageSize, pageNumber));
}
答案 0 :(得分:1)
您可以使用PagerOptions.ItemOptions.Default.Link
属性更改网址的生成方式:
<pager item-default-link='Sakura.AspNetCore.Mvc.PagerItemLinkGenerators.Format(Url.Content("~") + "/Clientes?page={0:d}")'/>