這裏是一個預計BookingDetail
和BookingVenue
對象我的WebAPI POST方法:如何將兩個對象傳遞給web api?
[HttpPost]
[ValidateUserSession]
public JsonResult CheckBooking(BookingDetail BookingDetail, BookingVenue objBV)
{
try
{
if (BookingDetail != null && objBV != null)
{
bool result = Ibook.checkBookingAvailability(BookingDetail, objBV);
if (result == false)
{
return Json("NotAvailable");
}
else
{
return Json("Available");
}
}
else
{
return Json("Available");
}
}
}
角碼從那裏我得到從UI的價值和製作後通過這2個對象:
this.checkbookingavailability = function (Book) {
var BookingVenueObj = {
EventTypeID: Book.EventSelected,
VenueID: Book.Venueselected,
GuestCount: Book.NoofGuest,
};
var BookingDetailObj = {
BookingDate: Book.BookingDate
};
var response =
$http({
method: "POST",
url: "/Booking/CheckBooking/",
headers: {
'RequestVerificationToken': $cookies.get('EventChannel')
},
data: { BookingDetail: BookingDetailObj, BookingVenue: BookingVenueObj }
});
return response;
}
問題是在我的WebAPI的代碼,都
您不能將兩個對象傳遞給web api。你可以這樣做:'public JsonResult CheckBooking([frombody] dynamic value)' –
@Div:我們可以在web api中傳遞兩個對象。 –
@ismail baig [看這裏](http://stackoverflow.com/questions/14407458/webapi-multiple-put-post-parameters) –