System.Collections.Generic.IEnumerable'不包含'ToList'的任何定义 [英] System.Collections.Generic.IEnumerable' does not contain any definition for 'ToList'

查看:29
本文介绍了System.Collections.Generic.IEnumerable'不包含'ToList'的任何定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题来了.我从 ViewPage 获取 IEnumerable,当我尝试将其转换为 List 时,它向我显示如下错误:

Here is the problem. I am getting IEnumerable from ViewPage and when I tried it to convert List it is showing me error like:

'System.Collections.Generic.IEnumerable' 不包含'ToList' 的定义和没有扩展方法 'ToList' 接受类型的第一个参数可以找到System.Collections.Generic.IEnumerable"(您是否缺少 using 指令或程序集引用?)

'System.Collections.Generic.IEnumerable<Pax_Detail>' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Pax_Detail>' could be found (are you missing a using directive or an assembly reference?)

这是我的控制器代码:

[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();
}

我在另一个控制器上应用了相同的逻辑.它工作正常.我不知道它有什么问题.我已经清理、重建项目并重新启动了我的笔记本电脑(尽管需要).

I have applied same logic on another controller. And it is working fine. I don't know what problem it has. I have already clean, rebuild project and also restarted my laptop(though it was needed).

推荐答案

您是否缺少 System.Linq 的 using 指令?

Are you missing a using directive for System.Linq?

http://msdn.microsoft.com/en-us/library/bb342261.aspx

这篇关于System.Collections.Generic.IEnumerable'不包含'ToList'的任何定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆