Why I get partial view data = null in the action post of the controller of main view ?
My Model:
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; }
}
My Main view:
@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>
}
My Partial View:
@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"))
)
)
My controller for the main view:
public ActionResult Save(WorkTimeRegulationViewModel x)
{
x.AssignedWorkTimes = null; //Why
return View();
}
Through firebug: The grid in edit mode :
<input class="k-textbox valid" id="Name" name="Name" data-bind="value:Name" aria-invalid="false">
After I use a prefix :
@Html.Partial("_WorkTime", Model.AssignedWorkTimes,
new ViewDataDictionary { TemplateInfo = new TemplateInfo { HtmlFieldPrefix = "AssignedWorkTimes" } })
I get the following:
<input class="k-textbox" id="AssignedWorkTimes_Name" name="AssignedWorkTimes.Name" data-bind="value:AssignedWorkTimes.Name">
but the collection still null!
Note: I have no controller for the partial view.
I don't know why x.AssignedWorkTimes = null