Posts

Showing posts with the label JSON

ASP.Net Core: Post JSON data to Api Controller

To post JSON data to web api controller in MVC Core is little bit change. public class StudentController : Controller { [ HttpPost ] public IActionResult AddStudent ( Student student ) { return Ok() ; } } public class Student { public string FirstName { get ; set ; } public string LastName { get ; set ; } public int Age { get ; set ; } } Here we have a model student and a Post Method in StudentController i.e. AddStudent.  So where does the  Student   parameter come from? Model binding to the rescue! There are a number of different places the model binders can look for data in order to hydrate the person object. The model binders are highly extensible, and allow custom implementations, but common bindings include: Route values - navigating to a route such as  {controller}/{action}/{id}  will allow binding to an  id parameter Querystrings - If you have passed variables as q...