c# - 将嵌套对象发送到asp.net core Get方法

标签 c# asp.net-core asp.net-core-webapi

我有以下模型对象

[DataContract]
public class Filter
{
    [DataMember (Name ="start")]
    public int Start { get; set; }

    [DataMember (Name="rows")]
    public int Rows { get; set; }

    [DataMember(Name = "geoloc")]
    public GeoLocationModel GeoLocation { get; set; }

}

[DataContract]
public class GeoLocationModel
{
    [DataMember(Name = "lat")]
    public double Latitude { get; set; }

    [DataMember(Name = "lng")]
    public double Longitude { get; set; }
}

和下面的 Action

    [HttpGet]
    public async Task GetCities([FromQuery]Models.Filters.Filter filters)
    {
        //some code
    }

当我使用以下查询(由 axios 生成的查询)调用我的操作时:

   /api/cities/?start=0&rows=5&geoloc=%7B%22lat%22:44,%22lng%22:3%7D

参数 Start 和 Rows 已正确填写,但 GeoLoc 为空。

我需要如何格式化我的查询以满足 FromQuery 属性?

最佳答案

您可以尝试这样的网址:/api/cities?start=4&rows=5&geoloc.Latitude=4&geoloc.Longitude=3

关于c# - 将嵌套对象发送到asp.net core Get方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57910279/

相关文章:

C# - MVC 4 多对多复选框值传递给另一个 View

c# - 如何在运行时向 DLL 添加代码

javascript - 在asp.net core中添加JavaScript引用

azure - .NET Core 5 的发布配置文件未显示在 Azure 中

c# - 从 C# 应用程序到 CRUD Cassandra 集群的最佳方法是什么

c# - 如何在字符串变量中包含转义序列

azure - Web应用程序在azure中出现http 404错误,但在本地运行

c# - 如何在 .Net Core Web API 中 Swagger 设置基本路径属性

c# - 在 .NET Core 2.1 中使用 AOP 进行日志记录

asp.net-web-api - 如何在 Identity 3 的 IUserTokenProvider 实现中生成 token ?