无法使用IEnumerable隐式转换类型

时间:2011-04-25 23:01:11

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

所以我在这个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&lt;&gt;中确实存在某些内容,我只是删除了它。

这是错误所在的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和存储库,没有来自那里的错误。

1 个答案:

答案 0 :(得分:0)

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