@using (Html.BeginForm("PrintDoorSigns", "TimeTable", FormMethod.Post, new { id = "printDoorSigns" }))
{
<input type="hidden" id="doorSignDate" name="SelectedDate" />
<h3>Door Signs</h3>
<fieldset class="float-left">
<legend>Date</legend>
<div id="signsDate"></div>
</fieldset>
<div id="doorSignsRoomList" class="float-left">
@{Html.RenderAction("DoorSignsForm", new { date = DateTime.Now });}
</div>
<div>
<fieldset>
<legend>Options</legend>
<button id="SelectAllRooms">Select All</button>
<button id="RemoveAllRooms">Remove All</button>
</fieldset>
</div>
}
我有此形式,其呈現此局部視圖:MVC 4模型局部視圖結合
@model WebUI.ViewModels.CalendarVM.DoorSignsFormVM
<fieldset>
<legend>Rooms</legend>
@{ var htmlListInfo = new HtmlListInfo(HtmlTag.vertical_columns, 3, null, TextLayout.Default, TemplateIsUsed.No);
if (Model.Rooms.Count() > 0)
{
<div id="roomsWithBookings" class="CheckBoxList float-left">
@Html.CheckBoxList("SelectedRooms", model => model.Rooms, entity => entity.Value, entity => entity.Text, model => model.SelectedRooms, htmlListInfo)
</div>
}
}
</fieldset>
控制器動作:
public ActionResult PrintDoorSigns(DateTime SelectedDate, DoorSignsFormVM Model)
當我提交表單,隱藏的輸入「 SelectedDate「傳回正常,包含兩個IEnumerable變量的Model變量不爲null。其中一個列表是空的,我期望,因爲它不應該傳回來,我預計將填充的SelectedRooms變量是一個新的列表與計數爲0.
我假設該綁定只是錯誤的這個屬性但我不明白爲什麼,任何指針?由於
編輯:
public PartialViewResult DoorSignsForm(DateTime date)
{
var userID = _bookingService.GetCurrentUser(User.Identity.Name);
var model = new DoorSignsFormVM();
model.Rooms = _sharedService.GetRoomsWithBookings(date, userID.FirstOrDefault().DefSite);
return PartialView("_DoorSigns", model);
}
這裏是獲取形式呈現的doorsignsform行動。
您不應該在這裏將DoorSignsFormVM模型傳遞給RenderAction方法Html.RenderAction(「DoorSignsForm」,new {date = DateTime.Now})?您可以發佈DoorSignsForm操作的代碼嗎? – devduder
添加到主要問題,謝謝 – Nathelol