简体   繁体   English

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

[英]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.

相关问题 C#-ASP.NET MVC从表单到控制器获取数据,我得到一个空对象 - C# - ASP.NET MVC Get data from form to controller, I get an empty object 如何从ASP.net MVC程序中获取普通c#程序中的JSON数据? - How do I get JSON data in a plain c# program from a ASP.net MVC program? 使List对象与ASP.NET MVC3中前端的发布数据兼容 - Making the List object compatible with post data from frontend in ASP.NET MVC3 asp.net mvc中POST方法获取json数据 - Get json data from POST method in asp.net mvc 在C#/ ASP.NET中获取POST数据 - Get POST data in C#/ASP.NET 我如何在ASP.NET C#MVC3中将数据从数据表导出到Excel? - How can i export the data from a data table to excel in asp.net c# mvc3? 当我尝试将数据从 db 提取到 ASP.NET MVC 和 C# 中的 excel 文件中时,出现匿名类型错误 - I get an anonymous type error when I try to extract data from db into excel file in ASP.NET MVC & C# 无法保存使用ASP.NET C#Web窗体收到的Razorpay Webhook数据 - Unable to save Razorpay Webhook Data received using ASP.NET C# Web Forms 如何将POST和GET数据保存到会话中,并使用ASP.NET C#将其提取? - How do i save POST and GET data into a session and pull it up with ASP.NET C#? 如何从html表单获取数据并将其存储在ASP.Net MVC视图中的ac#变量中 - how to get data from html form and store it in a c# variable in ASP.Net MVC view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM