【发布时间】:2012-09-14 15:44:27
【问题描述】:
我会说一点英语。我试着问我的问题。
我有一个模型。它的名字是 Product.cs
Product
{
public int TypeId { get; set; }/*these are at the same time field of Type Table*/
public string TypeName { get; set; }
public int TradeMarkId { get; set; }/*at the same time field of TradeMark Table*/
public string TradeMarkName { get; set; }
public int ProductId { get; set; }/*at the same time field of TProduct Table*/
public string ProductName { get; set; }
public int TId { get; set; }
public int TMId { get; set; }
public List<TypeProduct> typeList { get; set; }
}
我的控制器页面
My controller
[HttpGet]
public ActionResult TradeMarkProduckAdd()
{
Product product = new Product();
TypeList typeList = new TypeList();
product = typeList.TypeListOf(product);
return View(product);//"This doesn't work"
}
它说一个类型错误 传入字典的模型项的类型为“TypeMark.Models.Product”,但此字典需要类型为“System.Collections.Generic.IEnumerable`1[TypeMark.Models.Product]”的模型项。
当我收到此错误时,我将 return View(product); 更改为 return View((IEnumerable)product); 但它没有再次工作。
查看页面
@using TypeTradeMark.Models
@model IEnumerable<Product>
@using (Html.BeginForm("AddProduct", "Home", FormMethod.Post))
{
@foreach(var item in Model as List<Product>)
{
@item.ProductName
@item.??//checkbox for every record
@item.??//dropdownlist for trademarks
}
}
类型列表类
TypeList class
public class TypeList
{
VtDataContext Vt = new VtDataContext();
public Product TypeListOf(Product typeListOf)
{
var query = (from c in Vt.Types select c);
typeListOf.typeList=new List<Type>(query.ToList());
return typeListof;
}
}
我的桌子
Type : TypeId, TypeName
TradeMark : TradeMarkId,TradeMarkName
TProduct : ProductId,ProductName,TId,TMId//TId relation with TypeId, TMId relation with TradeMarkId
我无法解决问题你能帮帮我吗?谢谢
【问题讨论】:
-
您的模型有点奇怪...您如何创建数据库?你必须支持已经存在的数据库,还是你自己创建它?
-
我创建了数据库。有错吗?
-
不,没有错,但我认为你的模型是错误的。如果我理解正确的话……你有这样的对象:产品、商标和产品类型。一种产品有一个商标,几种类型。例如,某些 aSer 笔记本有“aSer”商标,属于计算机技术、办公技术、技术、笔记本等产品类型。我说的对吗?
-
是 aSer 是商标,computer 是 Type,aSer computer 是 Tproduct 表记录。我的模型可能是错误的,但我想在模型中使用我的数据库的多个表字段。我不能在模型中使用一个表。例如我不能使用@model 商标。因为在我看来,我使用商标名称和产品名称和类型名称。
标签: asp.net-mvc drop-down-menu checkbox ienumerable