为什么我在主视图控制器的操作帖中获得部分视图数据= null?
我的模型:
public class WorkTimeRegulationViewModel
{
public Guid Id { get; set; }
public string Name { get; set; }
public byte NumberOfAvailableRotations { get; set; }
public IEnumerable<WorkTimeViewModel> AssignedWorkTimes { get; set; }
public IEnumerable<AllocationViewModel> EnroledParties { get; set; }
}
我的主视图:
@model TimeAndAttendance.web.ViewModels.WorkTimeRegulationViewModel
@{
ViewBag.Title = "WorkTimeRegulationForm";
Layout = "~/Views/Shared/_LayoutAR.cshtml";
}
<h4>TEST</h4>
@using (Html.BeginForm("Save", "WorkTimeRegulation"))
{
// IEnumerable<TimeAndAttendance.web.ViewModels.WorkTimeViewModel> WorkTimeViewModel = Model.
<div class="form-group">
@Html.LabelFor(m => m.Name)
@Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Name)
</div>
<div class="form-group">
@Html.LabelFor(m => m.NumberOfAvailableRotations)
@Html.Label("")
</div>
@Html.Partial("_WorkTime",Model.AssignedWorkTimes.ToList())
<div>
</div>
@Html.HiddenFor(m => m.Id)
// @Html.AntiForgeryToken()
<button type="submit" class="btn btn-primary">ٍSave</button>
}
我的局部视图:
@model IEnumerable<TimeAndAttendance.web.ViewModels.WorkTimeViewModel>
@(Html.Kendo().Grid(Model)
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Name);
columns.Bound(p => p.NumberOfWorkHours).Width(120);
columns.Bound(p => p.NumberOfShortDays).Width(120);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(500);
})
.ToolBar(toolbar => toolbar.Create()
.Editable(editable => editable.Mode(GridEditMode.InLine).ConfirmDelete("test").DisplayDeleteConfirmation("Test"))
// .HtmlAttributes(new { style = "height:550px;" })
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.Id))
.Create(update => update.Action("EditingInline_Create", "WorkTimeRegulation"))
.Read(read => read.Action("EditingInline_Read", "WorkTimeRegulation"))
.Update(update => update.Action("EditingInline_Update", "WorkTimeRegulation"))
.Destroy(update => update.Action("EditingInline_Destroy", "WorkTimeRegulation"))
)
)
我的主视图控制器:
public ActionResult Save(WorkTimeRegulationViewModel x)
{
x.AssignedWorkTimes = null; //Why
return View();
}
通过萤火虫: 处于编辑模式的网格:
<input class="k-textbox valid" id="Name" name="Name" data-bind="value:Name" aria-invalid="false">
使用前缀后:
@Html.Partial("_WorkTime", Model.AssignedWorkTimes,
new ViewDataDictionary { TemplateInfo = new TemplateInfo { HtmlFieldPrefix = "AssignedWorkTimes" } })
我得到以下信息:
<input class="k-textbox" id="AssignedWorkTimes_Name" name="AssignedWorkTimes.Name" data-bind="value:AssignedWorkTimes.Name">
但该集合仍然为空!
注意:我没有用于局部视图的控制器。
我不知道为什么x.AssignedWorkTimes = null