3
使用下面的代碼我IEnumerable的預訂房間總是有空值,當他們到達控制器時,它知道有多少個已預訂房間我送回,但是RoomID和NumRooms的值對於每個項目都是空的想法?MVC4 IEnumerable模型綁定總是爲空
我有以下視圖模型...
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));
}
良好的調用,工作,但我不得不JSON.stringify(信息)(我更新了第1篇文章)。感謝nemesv – NoseBagUK 2012-07-31 19:28:13