モデルから正しく取り込まれているビューがあります。ビューのカットダウンは次のとおりです。
@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 は null です。
[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; }
}
}
モデル データが null である理由はありますか?