我试图通过 foreach 循环向我的视图显示数据,但我无法定义@model 有人可以帮我吗?
这是我的服务方法
public IEnumerable<CategoryType> GetCatList()
{
ShopEntities context = new ShopEntities();
List<Category> produkty = context.Category.ToList<Category>();
return changeTypee(produkty);
}
private List<CategoryType> changeTypee(List<Category> categorie)
{
List<CategoryType> productTypes = new List<CategoryType>(); ;
CategoryType product = new CategoryType();
foreach (var c in categorie)
{
product.ID = c.ID;
product.Name = c.Name;
productTypes.Add(product);
}
return productTypes;
}
这是我的合同
[OperationContract()]
IEnumerable<CategoryType> GetCatList();
这是我的控制器方法
public ActionResult Index()
{
ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();
return View(proxy.GetCatList());
}
错误信息
Compiler Error Message: CS1579: foreach statement cannot operate on variables of type 'System.Web.Mvc.ViewPage<System.Collections.Generic.IEnumerable<Shop.Data.CategoryType>>' because 'System.Web.Mvc.ViewPage<System.Collections.Generic.IEnumerable<Shop.Data.CategoryType>>' does not contain a public definition for 'GetEnumerator'