简体   繁体   English

将一般 object JSX 内部的 object 列表发布(使用 fetch)到 ASP.Net Core API

[英]Post (using fetch) a List of object inside of general object JSX to ASP.Net Core API

I am using ReactJS and ASP.Net Web API我正在使用 ReactJS 和 ASP.Net Web API

This is the model:这是 model:

  public class Skill
{
  public int Id { get; set; }
  public string Description { get; set; }
}

public class RegisterProject
{
  public class Request
  {
    public string Objective { get; set; }
    public string Description { get; set; }
    public long UserId { get; set; }
    public int CurrencyId { get; set; }
    public int BudgetId { get; set; }

    public List<Skill> Skills = new List<Skill>();
  }

  public class Response : Models.Common.Generic

Controller: Controller:

   [HttpPost]
    [Route("[action]")]
    [EnableCors("AllowAllOrigin")]
    public ActionResult<Models.Main.RegisterProject.Response> postRegisterProject([FromBody] Models.Main.RegisterProject.Request registerProjectRequest)

In React JS在反应 JS

const handleSubmit = (e) => { console.log(formPublishProject); const handleSubmit = (e) => { console.log(formPublishProject);

fetch(global.config.url + "Project/postRegisterProject/", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Accept: "application/json",
  },
  body: JSON.stringify({
    Objective: "a",
    Description: "b",
    UserId: 1,
    CurrencyId: 1,
    BudgetId: 1,
    Skills: [
      { Id: 1, Description: "ReactJS" },
      { Id: 2, Description: "Html" },
    ],
  }),
})
  .then(function (response) {
    response.json().then(function (data) {
      console.log("llego aqui");
      console.log(data);
    });
  })
  .catch(function (err) {
    console.log("Fetch Error :-S", err);
  });

}; };

In the controller a debug image below I don't receive the list of skills, I don't know if my skills definition is wrong or Is there another problem?在controller下面的一个debug image我没有收到技能列表,不知道是我的技能定义错误还是有其他问题?

调试控制器

Please change skills like this请像这样改变技能

public List<Skill> Skills { get; set; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 ASP.NET Core Web API 中发布对象列表 - How to post list of object in ASP.NET Core Web API 使用 ASP.NET Core MVC 将带有文件的数据发布到 api (ASP.NET Core Web API) - Post data with files using ASP.NET Core MVC to api (ASP.NET Core Web API) ASP.NET Core Angular 7 Http Post - 需要复杂对象吗? - ASP.NET Core Angular 7 Http Post - Requires Complex Object? 如何将 Typescript Map 对象发布到 ASP.Net Core WebAPI? - How to post Typescript Map object to ASP.Net Core WebAPI? Blazor / C# / ASP.NET 核心 MVC:在 object 中添加一个列表 - Blazor / C# / ASP.NET Core MVC: adding a list inside an object asp.net web api - 将对象发布到 web api - asp.net web api - post a object to web api Not getting multiple select list json array in object parameter in api controller Asp.net Core 2.1 - Not getting multiple select list json array in object parameter in api controller Asp.net Core 2.1 ASP.NET Core web api 序列化对象的List类型属性 - ASP.NET Core web api serialize an object's List type property 如何使用 AJAX POST 对象并使用 ASP.NET Core MVC 控制器获取? - How to POST object using AJAX and get with ASP.NET Core MVC controller? 发布带有文件上传到 asp.net core api 的对象/键值 - Posting object/keyvalue with file upload to asp.net core api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM