我会说一点点英语。我试着问我的问题。
我有一个模型。它的名字是 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]”的模型项.
当我收到此错误时,我更改了返回视图(产品);返回 视图((IEnumerable)产品);但它没有再次工作。
查看页面
@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
我无法解决问题你能帮帮我吗?谢谢