从前端我发送一个POST请求,其中包含以下数据:我无法更改以下结构:
我正在尝试获取“过滤器”数据。
我为以下数据创建了一个Model,如下所示:
namespace Project.Models
{
public class FooBar
{
public int skip { get; set; }
public int page { get; set; }
public Object filter { get; set; }
}
}
但是,当尝试从POST请求中提取数据时,我得到跳过/页面变量,但只是得到{object}的过滤器,我无法扩展
我的控制器写得像:
public HttpResponseMessage Foo([FromBody] FooBar request)
{
...
}
为什么我无法展开对象或访问它的任何属性,我该如何更改?
尝试在模型中重现请求结构并将其用作操作参数。
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){
//...
}