使用下面的代码,我的 IEnumerablebookedRooms 在到达控制器时总是有空值,它知道我发回了多少个bookedRooms,但是对于每个项目,RoomID 和 NumRooms 的值总是为空有什么想法吗?
我有以下视图模型...
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));
}