TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
osyris zosar
NA
289
26.9k
Try to pass model in ViewModel into the Detail action
Apr 3 2021 6:26 AM
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
; }
// etc...
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>
Reply
Answers (
6
)
how to make watsUp massenger using asp c#
Send Email in Cofoundry.