我的模型:
public class SendFileDeviceViewModel
{
public SendFileDeviceViewModel()
{
PolicyList = new List<SendFileDevicePoliciesViewModel>();
}
public string DeviceName { get; set; }
public int DeviceId { get; set; }
public string ManagementGroupName { get; set; }
public int ManagementGroupId { get; set; }
public bool ReloadConfiguration { get; set; }
public bool ImmediateSend { get; set; }
public DateTime TimeToSend { get; set; }
public List<SendFileDevicePoliciesViewModel> PolicyList { get; set; }
}
public class SendFileDevicePoliciesViewModel
{
public int PackageTemplateId { get; set; }
public string PolicyName { get; set; }
public string PolicyType { get; set; }
public string DefinedAt { get; set; }
public bool ResendPolicy { get; set; }
}
我的观点:
<h2>Send files to a Device @Model.DeviceName</h2>
<h3>Reload configuration settings</h3>
@Html.CheckBoxFor(m => m.ReloadConfiguration) @Html.LabelFor(m => m.ReloadConfiguration)
<h3>Select the policies to reload</h3>
@using (Html.BeginForm())
{
@Html.HiddenFor(m => m.DeviceId)
@Html.HiddenFor(m => m.ManagementGroupId)
@Html.ValidationSummary(true)
if (Model.PolicyList.Count() > 0)
{
<table>
<caption>
Policies available for this device</caption>
<thead>
<tr>
<th scope="col">
</th>
<th scope="col">
Policy Name
</th>
<th scope="col">
Policy Type
</th>
<th scope="col">
Defined At
</th>
</tr>
</thead>
<tbody>
@foreach (var policies in Model.PolicyList)
{
<tr>
@*<td>@Html.CheckBox("PackageTemplateId", new { value = policies.PackageTemplateId })</td>*@
<td>@Html.CheckBoxFor(m => policies.ResendPolicy)</td>
<td>@policies.PolicyName</td>
<td>@policies.PolicyType</td>
<td>@policies.DefinedAt</td>
</tr>
}
</tbody>
</table>
}
<div class="editor-label">
@Html.LabelFor(m => m.ImmediateSend)
</div>
<div class="editor-field">
@Html.CheckBoxFor(m => m.ImmediateSend)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.TimeToSend)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.TimeToSend)
</div>
<p>
<input type="submit" value="Send files" /></p>
我的问题是从控制器检索模型时,PolicyList 始终为空。我在这里错过了一些简单的事情吗?