If have created a Viewmodel:
- public async Task<IActionResult> Details(Guid? id)
- {
-
- if (id == null)
- {
- return NotFound();
- }
- ProductDetailViewModel productview = new ProductDetailViewModel()
- {
- productImages = await _context.ProductImages.FirstOrDefaultAsync( c => c.ProductId == id), //error
- productWithImagesDbs = await _context.ProductWithImagesDb.FirstOrDefaultAsync(m=> m.ProductId == id) // error
-
- };
-
- if (productview == null)
- {
- return NotFound();
- }
- return View(productview);
- }
the viewmodel:
- public class ProductDetailViewModel
- {
- public List<ProductWithImagesDb> productWithImagesDbs { get; set; }
- public List<ProductImages> productImages { get; set; }
- }
the model:
- public class ProductImages
- {
- [Key]
- [Required]
- public Guid ProductId { get; set; }
- [Required]
- public string ImagePath { get; set; }
- [Required]
- public int ImageOrder { get; set; }
- }
- public class ProductWithImages
- {
- [Key]
- [Required]
- public Guid ProductId { get; set; }
- [Required]
- [Display(Name ="Product Title")]
- public string ProductTitle { get; set; }
-
Its probaly something really simple that i dont know about yet. but i can seem to figure it out
it gives the error : Cannot implicitly convert type Test4.Models.ProductImagesDb to System.Collections.Generics.List<Test4.models.ProductImagesDb>