arrays - 无法将数组类型查询字符串解析为对象列表

标签 arrays asp.net-core-mvc custom-model-binder

我正在尝试在 ASP.net 核心 MVC 6 应用程序中进行一些分页和排序。但是当我传递像查询字符串这样的数组时,MVC 操作无法将其解析为列表。

查询字符串看起来像:

take=10&skip=0&page=1&pageSize=10&sort%5B0%5D%5Bfield%5D=price&sort%5B0%5D%5Bdir%5D=asc

它的模型看起来像:

enter image description here

这是我在服务器上得到的查询字符串: enter image description here

排序数组或列表的计数始终为 0。 enter image description here

能否请您提出解决方法。它应该正确地解析它,但没有找到错误的地方。

最佳答案

你当前解码后的查询字符串看起来像

take=10&skip=0&page=1&pageSize=10&sort[0][field]=price&sort[0][dir]=asc

因此使用以下格式从您的客户端应用程序传递查询字符串参数

sort[0].field=price&sort[0].dir=asc

关于arrays - 无法将数组类型查询字符串解析为对象列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41464217/

相关文章:

iis - 在安装了 Core 2.1 的 IIS 10 服务器上,针对 Core 2.1 构建的 ASP.NET Core 应用程序失败

c# - Asp.Net Core 中 Kendo Grid 中的 DropDownList

asp.net-mvc-3 - MVC 3 自定义模型绑定(bind)到平面变量结构

c# - AspNet Core WebApi 中的自定义模型绑定(bind)?

python - "Setting an array element with a sequence"numpy 错误

angularjs - 如何在 MVC6 项目中安装 Angular2?

php - 使用 Laravel View::share 访问共享数组中的项目

asp.net-mvc-3 - 在自定义模型绑定(bind)后验证 View 模型

ios - iOS如何复制/引用C-Array?

c++ - 调用堆栈上大量对象的构造函数