使用下面的代码后,我的IEnumerable bookedRooms在到达控制器时总是有空值,它知道我发送回了多少bookedRooms,但每个条目的RoomID和NumRooms值总是为null,有什么想法吗?
我有以下视图模型...
我正在使用以下的jQuery AJAX调用..
我有以下视图模型...
public class SelectDatesViewModel
public int venueID { get; set; }
public IEnumerable<BookedRoomViewModel> bookedRooms {get;set;}
public string checkInDateString { get; set; }
public int pageNo { get; set; }
public bool showCheckIn { get; set;}
public string startDateString { get; set; }
}
public class BookedRoomViewModel
{
public string RoomID { get; set; }
public string NumRooms { get; set; }
}
我正在使用以下的jQuery AJAX调用..
function showArrivalCalendar() {
showThrobber();
var info = {
venueID: venueID,
bookedRooms: getBookedRooms(),
startDateString: $("#calendarHolder").data("arrivalstartdate"),
checkInDateString: "",
pageNo: 1,
showCheckIn: true
}
$.ajax({
url: "/Booking/BookingCalendar/",
type: "POST",
data: JSON.stringify(info),
dataType: "json",
success: function (retValue) {
$("#calendarHolder").html(data);
hideThrobber();
}
});
}
function getBookedRooms() {
var bookedRooms = [];
$("#selectBookingType").find("select").each(function () {
if ($(this).find(":selected").val() > 0) {
var noRooms = $(this).find(":selected").val();
bookedRooms.push({
RoomID: $(this).data("roomid"),
NumRooms: noRooms
});
};
});
return bookedRooms;
}
发布到此控制器..
[HttpPost]
public ActionResult BookingCalendar(SelectDatesViewModel model)
{
return PartialView(GetBookingDates(model.venueID, model.startDateString, model.showCheckIn, model.pageNo, model.checkInDateString));
}