无法使用 IEnumerable 隐式转换类型
所以我正在努力开发这个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了这些错误,这是我的错,因为我从 DAL/存储库调用了错误的方法。
Got those errors resolved, it was my fault because I was calling the wrong methods from the DAL/Repository.