我有一个从模型正确填充的视图。这是视图的缩减:
@model PickardOrdering.Models.ExhibitionItemModel
@foreach (var item in Model.Items)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.Code)</td>
<td>@Html.DisplayFor(modelItem => item.Description)</td>
<td>@Html.CheckBoxFor(modelItem => item.AdditionalItem.Value, new { @disabled = "disabled" })</td>
<td>@Html.CheckBoxFor(modelItem => item.IsItemSelected.Value)</td>
<td>£ @Html.EditorFor(modelItem => item.ItemPrice)</td>
</tr>
}
<input type="submit" value="Save Items" />
当我将数据发布回控制器时, Exhibitionitemmodel 为空:
[HttpPost, ActionName("CreateExhibitionItems")]
public ActionResult CreateExhibitionItems(ExhibitionItemModel exhibitionitemmodel)
{
decimal decPrice;
if (ModelState.IsValid)
{
List<tblExhibitionItem> lstExhibitionItem = new List<tblExhibitionItem>();
IEnumerable<ItemWrapper> lstItemWrapper = from objExhibitionItemModel in exhibitionitemmodel.Items
select objExhibitionItemModel;
这是使用的模型类:
namespace PickardOrdering.Models
{
public class ItemWrapper : tblItem
{
public decimal ItemPrice { get; set; }
public bool? IsItemSelected { get; set; }
}
public class ExhibitionItemModel
{
public IEnumerable<ItemWrapper> Items { get; set; }
public tblExhibition Exhibition { get; set; }
public IEnumerable<tblExhibitionItem> ExhibitionItems { get; set; }
}
}
任何想法为什么模型数据为空?