c# - 在 ASP.Net Core 中使用分页传递模型参数
问题描述
我正在使用 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)
{
}
模型始终为 null,并且不包含任何模型值。我如何解决它?
解决方案
您无法使用asp-route-{value}
or传递整个模型对象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>
它将作为查询字符串工作。
https://forums.asp.net/t/1984183.aspx?Passing+Model+Object+in+route+values+of+Action+link
推荐阅读
- ios - Flutter IOS:CocoaPods 找不到 pod“simple_permissions”的兼容版本:
- oracle - 无法使用的分区 Oracle / datastage
- python - 使用 pandas 将输出写入另一个文件
- c++ - 如何对齐 QTextEdit 文本
- angularjs - 分页不保持页面导航之间的页面状态
- c# - 在注销剃须刀页面上禁用获取请求
- openssl - i2d_ASN1_OBJECT 问题
- server - ns3 脚本的输出,其中 evalvid 服务器通过 802.11 向客户端发送数据包
- sql - 仅显示周一至周日整周的数据顺序并隐藏非整周数据
- html - 有什么区别
和 我是学习者,我想知道什么是 diff b/w ionic 和 HTML 标签,哪些标签适用于混合移动开发应用程序,有人可以建议我下面的两个代码在我的移动应用程序中运行良好,但哪些标签是最可取的?
<div class="list"> <div class="item it