【问题标题】:.net core model binding standard different from .net 4.6.net 核心模型绑定标准不同于 .net 4.6
【发布时间】:2017-06-06 11:22:54
【问题描述】:

从 .net 4.6 迁移到 .net core 1.1 后,Model Binding 的接受程度大不相同,如下:

  • 对于 .net 4.6,模型绑定通过接受请求参数(查询字符串)来工作,如下所示

    边界[TopLeft][Lat]:10.808969811804062
    边界[TopLeft][Lon]:106.63826676953124
    边界[BottomRight][Lat]:10.785699937603939
    边界[BottomRight][Lon]:106.72066423046874
    中心[纬度]:10.7973351
    中心[lon]:106.6794655
    限制:1000

  • 对于.net core 1.1,模型绑定通过接受请求参数(查询字符串)来工作,如下所示

    Boundary.TopLeft.Lat:10.808969811804062
    Boundary.TopLeft.Lon:106.63826676953124
    Boundary.BottomRight.Lat:10.785699937603939
    Boundary.BottomRight.Lon:106.72066423046874
    Center.lat:10.7973351
    Center.lon:106.6794655
    限制:1000

因此,来自客户端的所有查询都失败了(模型绑定显示空对象)。 .net 核心是否有任何配置可以接受 Boundary[TopLeft][Lat] 而不是 Boundary.TopLeft.Lat?

【问题讨论】:

  • 更准确地说,我使用jQuery执行ajax请求(GET/POST)来查询边界用户,jQuery将请求的数据解析为Boundary[TopLeft][Lat],完全没有问题使用 .net 4.6 API。但是,.net core 1.1 需要 Boundary.TopLeft.Lat 格式,否则将无法读取。

标签: asp.net-core model-binding


【解决方案1】:

从 npm 中找到了一个很酷的库,它是“qs”,它可以将“allowDots”选项设置为“true”来对数据进行字符串化。然后,它将对象解析为 Boundary.Top.Left 而不是 Boundary[Top][Left]

【讨论】:

    猜你喜欢
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多