我想列出视图中的国家。我创建了一个名为tbl_Countries的模型,代码是ASP.Net MVC剃刀 - 显示器国家给出错误的视图
public class tbl_Countries
{
public int ID { get; set; }
public string Country_Name { get; set; }
}
我有一个名为Home的控制器,其代码如下。我已经创建了数据库TESTDB的EDMX文件
public ActionResult Index()
{
TestDBEntities TestdbContext = new TestDBEntities();
var countries = TestdbContext.tbl_Countries.ToList();
return View(countries);
}
下面是我查看代码 @model的IList 显示使用UL里用foreach
的国家。如果我运行该应用程序正在此错误:
The model item passed into the dictionary is of type 'System.Collections.Generic.List1[TestMVC.tbl_Countries]',
but this dictionary requires a model item of type 'System.Collections.Generic.IList1[TestMVC.Models.tbl_Countries]
我只想显示在视图中的国家列表,我想知道 没有创建模型类是否可以绑定网格? 是否必须使用@model
指令来指定型号名称?
请展现您的观点 – 2013-03-28 09:04:46