我正在使用PagedList在ASP.Net Core应用程序的表上工作。我需要在页面更改时将模型传递给控制器,但是没有发送出去。
视图中代码的分页部分为
<pager class="pager" list="@Model.UserList" asp-action="Index" asp-controller="User" asp-route-model ="@Model" param-page-number="page" options="@PagedListRenderOptions.ClassicPlusFirstAndLast" />
我的控制器签名是:
public ActionResult Index(UsersModel model, int? page)
{
}
模型始终为空,不包含任何模型值。我该如何解决?
您无法使用asp-route-{value}
或asp-all-route-data
传递整个模型对象。
[asp-route用于string
类型,asp-all-route-data用于IDictionary<string,string>
类型
我建议您可以像这样手动传递模型数据
@{
var parms = new Dictionary<string, string>
{
{ "Id",Model.Id.ToString() },
{"Name",Model.Name },
//...
};
}
<a asp-action="Index" asp-controller="User" asp-all-route-data="parms">Test</a>
它将作为queryString。