Can anyone please help me to pass multiple models as a parameter to the request's content in WEB API?
I have 2 different Model Student and Employee
- public class Student
- {
- public int StudentId { get; set; }
- public string StudentName { get; set; }
- public string Branch { get; set; }
- }
-
- public class Employee
- {
- public int EmployeeId { get; set; }
- public string EmployeeName { get; set; }
- public string Department { get; set; }
- }
I have created an API and want to pass both these models as parameters in my action method InsertTestAPI.
- [HttpPost]
- [Route("TestAPI")]
-
- public HttpResponseMessage InsertTestAPI(Student modelStudent, Employee modelEmployee)
- {
-
- }
When I pass these models as JSON in the request body, I get the following error in Postman.
- {
- "$id": "1",
- "Message": "An error has occurred.",
- "ExceptionMessage": "Can't bind multiple parameters ('modelStudent' and 'modelEmployee') to the request's content.",
- "ExceptionType": "System.InvalidOperationException",
- "StackTrace": " at System.Web.Http.Controllers.HttpActionBinding.ExecuteBindingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()"
- }
Can anyone please help me?