我会一点英语,尝试提出我的问题。
我有一个模型,它的名字是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"
}
错误提示为类型错误,字典要求的模型项类型是'System.Collections.Generic.IEnumerable`1[TypeMark.Models.Product]', 但传入的模型项类型为 '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
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
我无法解决这个问题,你能帮我吗?谢谢。