【问题标题】:Cannot implicitly convert type with IEnumerable无法使用 IEnumerable 隐式转换类型
【发布时间】:2011-04-25 23:01:10
【问题描述】:

所以我正在努力开发这个 MVC 应用程序,并且一切运行顺利。我起床准备吃点东西,下次构建时遇到以下 4 个错误:

> Error 16  Cannot implicitly convert type
> 'System.Collections.Generic.IEnumerable<>
> [c:\Program Files (x86)\Reference  Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll]'
> to
> 'System.Collections.Generic.IEnumerable<>
> [c:\Program Files (x86)\Reference  Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll]'.
> An explicit conversion exists (are you missing a cast?)

请记住,IEnumerable中实际上有一些东西,我只是将其删除。

这是错误所在的 2 个类

    public partial class PriceListController : Controller
    {

        [CanonicalUrlAttribute("PriceList")]
        [CompressionFilter(Order = 1)]
        [CacheFilter(Duration = 120, Order = 2)]
        public virtual ActionResult Index()
        {
            GodsCreationTaxidermyEntities context = new GodsCreationTaxidermyEntities();
            var viewModel = new PriceListViewModel() { PriceListAnimals = context.GetAnimalListForPriceList() };
            return View(viewModel);
        }


        [CompressionFilter(Order = 1)]
        [CacheFilter(Duration = 120, Order = 2)]
        public virtual ActionResult List(string animal)
        {
            GodsCreationTaxidermyEntities context = new GodsCreationTaxidermyEntities();

            var viewModel = new PriceListIndexViewModel() { AnimalPrices = context.GetPriceListByAnimal(animal) };
            return View(viewModel);
        }

    }
public partial class GalleryController : Controller
{
    //
    // GET: /Gallery/
    [CanonicalUrlAttribute("Gallery")]
    [CompressionFilter(Order = 1)]
    [CacheFilter(Duration = 120, Order = 2)]
    public virtual ActionResult Index()
    {
        GodsCreationTaxidermyEntities context = new GodsCreationTaxidermyEntities();
        var viewModel = new GalleryIndexViewModel() { GalleryAnimals = context.GetAnimalListForGallery() };
        return View(viewModel);
    }


    [CompressionFilter(Order = 1)]
    [CacheFilter(Duration = 120, Order = 2)]
    public virtual ActionResult List(string animal)
    {
        GodsCreationTaxidermyEntities context = new GodsCreationTaxidermyEntities();

        var viewModel = new GalleryListViewModel() { GalleryImages = context.GetGalleryImageByAnimal(animal) };
        return View(viewModel);

    }

}

我检查了 DAL 和存储库,没有出现任何错误。

【问题讨论】:

  • 也许你在异常发生的地方展示了一些代码?
  • IIS 我假设?尝试运行 IISReset 实用程序来重置服务器(必须以管理员身份运行),然后重建。
  • 嗯,我们可以看到更多代码吗?它究竟在哪里抛出异常?
  • 奇怪的是,当我去吃晚饭时它运行了,但是当我回来时,我得到了所有这些错误。
  • 是否显示异常发生在哪一行?

标签: asp.net asp.net-mvc-2


【解决方案1】:

解决了这些错误,这是我的错,因为我从 DAL/存储库中调用了错误的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-09
    相关资源
    最近更新 更多