【发布时间】:2011-09-06 20:53:15
【问题描述】:
我在尝试渲染 asp.net MVC 3.0 应用程序时遇到了这个错误。 我正在使用 DAB 架构(3 个项目)CAFM.Web、CAFM.Business 和 CAFM.Data 项目。
CAFM.Data 包括
CAFMEntities : 实体框架 ITabMaster : 接口 命名空间 CAFM.Data.Interfaces { 公共接口 ITabMaster { TabMaster GetTabMasterById(Int64 id); IEnumerable FindTabMasterByName(字符串名称); void AddTabMaster(TabMaster tabmaster); IEnumerable GetAllTabMaster(); } }
CAFM.Business 包括 CAFM.Data的参考 命名空间 CAFM.Business.Repositories { 公共类 TabMasterRepository : ITabMaster { 公共 int colID { 获取;放; } 公共字符串名字 { 获取;放; } 公共字符串姓氏{得到;放; }
private CAFMEntities _context;
public TabMasterRepository()
{
//IUnitOfWork unitOfWork = new CAFMEntities();
_context = new CAFMEntities();
}
public TabMasterRepository(IUnitOfWork unitOfWork)
{
if (unitOfWork == null)
throw new ArgumentNullException("unitOfWork");
_context = unitOfWork as CAFMEntities;
}
public IEnumerable<TabMaster> GetAllTabMaster()
{
//(extension)List<Movie> IEnumerable<Movie>.ToList<Movie>()
//List<TabMaster> tabmasters = _context.TabMasters.ToList();
return _context.TabMasters.ToList() ;// .AsEnumerable<TabMaster>();//.ToList();
//return tabmasters;
}
public TabMaster GetTabMasterById(Int64 id)
{
return _context.TabMasters.Where(c => c.colID == id).Single();
}
public IEnumerable<TabMaster> FindTabMasterByName(string name)
{
return _context.TabMasters.Where(c => c.LastName.StartsWith(name)).AsEnumerable<TabMaster>(); //.ToList();
}
public void AddTabMaster(TabMaster tabmaster)
{
_context.TabMasters.AddObject(tabmaster);
}
}
}
CAFM.Web 包括 CAFM.Data的参考 命名空间 CAFM.Web.Controllers { 公共类 TabMasterController : 控制器 { // // GET: /TabMaster/
public ViewResult Index()
{
//Error comes in following line. (_context.TabMasters.ToList() is successfully return all the values but error is The model item passed into the dictionary is ... during rendering HTML
TabMasterRepository tr = new TabMasterRepository();
return View(tr.GetAllTabMaster());
}
}
}
Index.cshtml 包含
@model IEnumerable @{ 布局=空; } 标签大师
电影列表
@Html.ActionLink("新建", "创建")
ID 名 姓 @foreach(模型中的变量项) { @Html.DisplayFor(modelItem => item.colID) @Html.DisplayFor(modelItem => item.FirstName) @Html.DisplayFor(modelItem => item.LastName) }错误说明:
传入字典的模型项的类型为“System.Collections.Generic.List1[CAFM.Data.TabMaster]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[CAFM.Business.Repositories.TabMasterRepository]”。
请提供您宝贵的建议以解决上述错误。
您的回答将不胜感激! 谢谢, 伊姆达杜森
【问题讨论】: