无法使用 IEnumerable 隐式转换类型

发布于 2024-11-03 10:42:47 字数 2427 浏览 0 评论 0原文

所以我正在努力开发这个 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 和存储库,没有发现任何错误。

So I'm chugging along on this MVC application and all is running smoothly. I get up to fix a bite to eat and the next time I build I'm greeted with 4 of these errors:

> 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?)

Keep in mind that there is actually something in IEnumerable<>, I just removed it.

This is the 2 classes where the errors are at

    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);

    }

}

I've checked the DAL and Repository and no errors coming from there.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上芳菲 2024-11-10 10:42:47

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

Got those errors resolved, it was my fault because I was calling the wrong methods from the DAL/Repository.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文