1. Student.cs namespace APIWebApplication.Models { public class Student { public int StuId { get; set; } public string StuName { get; set; } } } 2. ToDoController: using APIWebApplication.ModelBinder; using APIWebApplication.Models; using Microsoft.AspNetCore.Mvc; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace APIWebApplication.Controllers { [Route("api/[controller]")] [ApiController] public class ToDoController : ControllerBase { // POST api/ [HttpPost("AddStudent")] public IActionResult Post([ModelBinder(BinderType = typeof(CustomModelBinder))] Student student) { return Ok(student); } } } 3.Custom Model Binder: using APIWebApplication.Models; using Microsoft.AspNetCore.Mvc.ModelBinding; using Newtonsoft.Json; namespace APIWebApplication.ModelBinder { public class CustomModelBinderProvider : IModelBinderProvider { public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context.Metadata.ModelType == typeof(Student)) return new CustomModelBinder(); return null; } } public class CustomModelBinder : IModelBinder { public Task BindModelAsync(ModelBindingContext bindingContext) { if (bindingContext == null) throw new ArgumentNullException(nameof(bindingContext)); //if the content type is "application/x-www-form-urlencoded", get the value from the Request Form if (bindingContext.HttpContext.Request.ContentType== "application/x-www-form-urlencoded") { var student = new Student(); if(bindingContext.HttpContext.Request.Form.ContainsKey("StuId")) student.StuId = Convert.ToInt32(bindingContext.HttpContext.Request.Form["StuId"].ToString()); if (bindingContext.HttpContext.Request.Form.ContainsKey("StuName")) student.StuName = bindingContext.HttpContext.Request.Form["StuName"].ToString(); bindingContext.Result = ModelBindingResult.Success(student); } else if(bindingContext.HttpContext.Request.ContentType== "application/json") { //If the content type is "application/json", get the value from the request body. string valueFromBody = string.Empty; using (var sr = new StreamReader(bindingContext.HttpContext.Request.Body)) { valueFromBody = sr.ReadToEnd(); if (string.IsNullOrEmpty(valueFromBody)) { return Task.CompletedTask; } var student = JsonConvert.DeserializeObject(valueFromBody); if (student != null) { bindingContext.Result = ModelBindingResult.Success(student); } } } return Task.CompletedTask; } } } 4. Program.cs using APIWebApplication.ModelBinder; using Microsoft.AspNetCore.Server.Kestrel.Core; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); builder.Services.AddControllers(o=> o.ModelBinderProviders.Insert(0, new CustomModelBinderProvider())); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); // If using Kestrel: builder.Services.Configure(options => { options.AllowSynchronousIO = true; }); // If using IIS: builder.Services.Configure(options => { options.AllowSynchronousIO = true; }); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Run();