MVC controller : get JSON object from HTTP body?

前端 未结 5 567
闹比i
闹比i 2020-11-28 06:46

We have an MVC (MVC4) application which at times might get a JSON events POSTed from a 3rd party to our specific URL (\"http://server.com/events/\"). The JSON event is in th

5条回答
  •  情歌与酒
    2020-11-28 07:22

    I've been trying to get my ASP.NET MVC controller to parse some model that i submitted to it using Postman.

    I needed the following to get it to work:

    • controller action

      [HttpPost]
      [PermitAllUsers]
      [Route("Models")]
      public JsonResult InsertOrUpdateModels(Model entities)
      {
          // ...
          return Json(response, JsonRequestBehavior.AllowGet);
      }
      
    • a Models class

      public class Model
      {
          public string Test { get; set; }
          // ...
      }
      
    • headers for Postman's request, specifically, Content-Type

    • json in the request body

提交回复
热议问题