我有一個正在從模型正確填充的視圖。這裏是觀的切開術:從視圖傳遞給控制器的模型數據爲NULL
@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; }
}
}
模型數據爲空的任何想法?
表單標籤在哪裏? – 2013-02-18 16:51:40
好抓@YuriyRozhovetskiy – 2013-02-18 16:52:13