C#ASP.NET MVC - 无法获取从前端收到的POST数据的属性/数据

问题描述 投票:0回答:1

从前端我发送一个POST请求,其中包含以下数据:我无法更改以下结构:

enter image description here

我正在尝试获取“过滤器”数据。

我为以下数据创建了一个Model,如下所示:

namespace Project.Models
{
    public class FooBar
    {
        public int skip { get; set; }
        public int page { get; set; }
        public Object filter { get; set; }

    }
}

但是,当尝试从POST请求中提取数据时,我得到跳过/页面变量,但只是得到{object}的过滤器,我无法扩展

enter image description here

我的控制器写得像:

public HttpResponseMessage Foo([FromBody] FooBar request)
{
...

}

为什么我无法展开对象或访问它的任何属性,我该如何更改?

c# asp.net-mvc model
1个回答
1
投票

尝试在模型中重现请求结构并将其用作操作参数。

public class FilterPageModel  {
    public int skip { get; set; }
    public int page { get; set; }
    public Filter filter{ get; set; }
}   

public class Filter
{         
    public string logic{ get; set; }
    public List<FieldFilter> filters{ get; set; }
}

public class FieldFilter
{         
    public string field{ get; set; }
    public string operator{ get; set; }
    public string value{ get; set; }
}

然后在控制器中:

public ActionResult Foo (FilterPageModel model){
    //...
}
© www.soinside.com 2019 - 2024. All rights reserved.