TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nikunj Satasiya
183
10k
3.6m
How to pass multiple model as parameter in WEB API
Jan 28 2021 5:14 AM
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)
{
// other logical operations
}
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?
Reply
Answers (
5
)
json schema validation
how to install visual studio 2013 in windows 10 pro?