Methods for receiving JSON data in an Asp.NET core Controller

  1. [HttpPost] 
    public  IActionResult Fill([FromBody] dynamic data)
    {
         string amount = data.amount.GetString();
    }
    
  2.  [HttpPost] 
     public  IActionResult Fill()
     {
          string dataStr = new StreamReader(Request.Body, Encoding.UTF8).ReadToEnd();
          var data = JObject.Parse(dataStr);
          string amount = data.value.amount;
     }
    
  3. [HttpPost] 
    public  IActionResult Fill([FromBody] YourType data)
    {
        string amount = data.amount;
    }
    

Comments

  1. Markdown is allowed. HTML tags allowed: <strong>, <em>, <blockquote>, <code>, <pre>, <a>.