【发布时间】:2019-04-07 20:21:44
【问题描述】:
我正在从 PostMan 发送 POST:
并且参数不断出现为空。根据我的阅读,更改Post([FromBody]Models.Question value) 并设置模型应该能够处理传入的json 参数。我想我缺少一个设置或者我不明白如何正确处理json 数据。
QuestionsController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace quiz_backend.Controllers
{
[Produces("application/json")]
[Route("api/Questions")]
public class QuestionsController : Controller
{
// POST api/values
[HttpPost]
public void Post([FromBody]Models.Question value)
{
}
}
}
型号是
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace quiz_backend.Models
{
public class Question
{
public string Text{ get; set; }
}
}
【问题讨论】:
-
在您的请求正文中,您的请求有效负载似乎是
{"test":"test"}。应该是{"Text": "text sample"} in order to match the object propertyText`。
标签: c# asp.net asp.net-core asp.net-core-2.0 asp.net-web-api-routing