Please forgive me if I'm not providing the right information, I'm a newbie with this MVC thing.
I am using the LINQ statement below, the problem is the Image URL is not displaying. Any ideas why? Thanks in advance
Controller:
public ActionResult Index()
{
var cars = from c in db.Cars
from m in db.Makes from u in db.CarImages
where c.carID == m.makeID && u.CarID == c.carID && (u.thumbnail.Equals("true"))
select c;
return View(cars.ToList());
}
View:
@Html.DisplayFor(modelItem => item.CarImage.imageUrl)
A bit more info: I used the code first approach.
Car Model:
public class Car
{
public int carID { get; set; }
public int makeID {get; set;}
public string registration { get; set; }
public string color { get; set; }
public Decimal price { get; set; }
public string fuel { get; set; }
public DateTime tax { get; set; }
public DateTime mot { get; set; }
public DateTime manufactureDate { get; set; }
public string shortDescription { get; set; }
public string longDescription { get; set; }
public virtual Make Make { get; set; }
public virtual CarModel CarModel { get; set; }
public virtual CarImage CarImage { get; set; }
}
CarImage Model
public class CarImage
{
public int CarImageID { get; set; }
public int CarID { get; set; }
public string imageUrl { get; set; }
public string thumbnail { get; set; }
}
Make Model
public class Make
{
public int makeID { get; set; }
public string makeName { get; set; }
}
DBContext
public class CarStudioDBContext : DbContext
{
public DbSet<Car> Cars { get; set; }
public DbSet<Make> Makes { get; set; }
public DbSet<CarImage> CarImages { get; set; }
public DbSet<CarModel> CarModels { get; set; }
}
Thanks for the help guys