【发布时间】:2014-05-09 19:46:08
【问题描述】:
得到一个我不明白的错误: "传入字典的模型项为空, 但是这个字典需要一个'System.Decimal'类型的非空模型项。” 发生在视图中的这一行:
<td>@Html.EditorFor(model => model.Price)</td>
它应该为空。这是一个创建产品页面。这是代码:
public ActionResult Create()
{
var items = new ProductItems();
return View(items.Products);
VIEW :
@using Nop.Web.Models.Products
@model ProductItems
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<tr>
<td>@Html.EditorFor(model => model.Price) << error here
VIEW MODEL :
public class ProductItems
{
public decimal Price { get; set; }
public IEnumerable<Product> Products { get; set; }
NOTE : I previously changed the View Model. It was :
@model Nop.Core.Domain.Catalog.Product
and it worked before I changed it.
是什么导致了这个错误?谢谢
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 razor