将查询字符串转换为模型类

时间:2020-02-17 16:57:35

标签: asp.net-web-api

我有一个查询字符串需要在Rest Api中转换为Model ?search=&pageSize=20&page=1&_o._f%5B0%5D._i=false&_o._f%5B0%5D._n=Gender&_o._f%5B0%5D._v=%5B1%5D

我的密码

 public async Task<IActionResult> GetList([FromQuery] CustomViewBody body)

 public class CustomViewBody
    {
        public string Search { get; set; }
        public int Page { get; set; } = 1;
        public int PageSize { get; set; } = 20;
        [JsonProperty(PropertyName = "_o")] public ViewOptions Options { get; set; }
    }

 public class ViewOptions
    {
        [JsonProperty(PropertyName = "_f")] public ViewFilter[] Filters { get; set; }

        [JsonProperty(PropertyName = "_s")] public ViewSort[] Sorts { get; set; }
        public string[] Columns { get; set; }

        // public bool ShowTotal { get; set; }
    }

但是根据我的要求Options始终为null。如果切换到POST方法,此代码将运行,但会破坏Rest Api的结构

0 个答案:

没有答案