[英]C# ASP.NET MVC - Unable to get the properties/data of POST data I received from the frontend
From the front end I am sending a POST request with the following data that I cannot change the structure of: 我将从前端发送包含以下数据的POST请求,但无法更改其结构:
I am trying to get the "filter" data. 我正在尝试获取“过滤器”数据。
I created a Model for the following data as follows: 我为以下数据创建了一个模型,如下所示:
namespace Project.Models
{
public class FooBar
{
public int skip { get; set; }
public int page { get; set; }
public Object filter { get; set; }
}
}
However when trying to extract the data from the POST request I get the skip/page variables but just get {object} for filter that I am unable to expand upon 但是,当尝试从POST请求中提取数据时,我得到了skip / page变量,但仅得到{object}作为过滤器,我无法对其进行扩展
The controller I have is written like: 我拥有的控制器是这样写的:
public HttpResponseMessage Foo([FromBody] FooBar request)
{
...
}
Why am I unable to expand the object or access any properties of it and how can I change this? 为什么我无法展开对象或访问它的任何属性,如何更改它?
Try to reproduce request structure in your model and use it as action parameter. 尝试在模型中重现请求结构并将其用作操作参数。
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; }
}
And then in controller: 然后在控制器中:
public ActionResult Foo (FilterPageModel model){
//...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.