这是问题所在.我从ViewPage获得IEnumerable,当我尝试转换List时,它显示的错误如下:
'
System.Collections.Generic.IEnumerable<Pax_Detail>'不包含'ToList'的定义,并且没有System.Collections.Generic.IEnumerable<Pax_Detail>可以找到接受类型' ' 的第一个参数的扩展方法'ToList' (你是否缺少using指令或汇编引用?)
这是我的控制器代码:
[HttpPost]
public ActionResult Edit_Booking(Booking model, IEnumerable<Pax_Detail> pax)
{
List<Pax_Detail> paxList = new List<Pax_Detail>();
paxList = pax.ToList(); //getting error here
BookingDL.Update_Booking(model, paxList);
return View();
}
Run Code Online (Sandbox Code Playgroud)
我在另一个控制器上应用了相同的逻辑.它工作正常.我不知道它有什么问题.我已经清理,重建项目,并重新启动我的笔记本电脑(虽然它是必要的).
当尝试从模型执行我的数据库上下文中的.Where()时,我遇到以下错误消息:
System.Data.Entity<RPSManagementSystem.Model.StoreUser> does not contain a definition for Where...
Run Code Online (Sandbox Code Playgroud)
这在从控制器调用时有效.是什么赋予了?
从模型:
[NotMapped]
private List<StoreUser> _stores { get; set; }
[NotMapped]
public List<StoreUser> Stores
{
get
{
if (this._stores == null || this._stores.Count <= 0)
{
using (RPSEntities db = new RPSEntities())
{
this._stores = db.StoreUsers.Where(su => su.Username == this.Username);
}
}
return _stores;
}
}
Run Code Online (Sandbox Code Playgroud)
为了确保我没有疯狂,我将它粘贴到我的控制器中 - 它看起来在起作用.屏幕截图如下:
在模型中:

在控制器中:
