Hello, I'm just starting to learn ASP.NET MVC. I have a problem with displaying the details of the owner, the name is displayed, the last name, but information about the machine is not displayed. I did it on the example from the Microsoft website for learning ASP.NET. public class Owner {
public int OwnerID { get; set; } public string Name { get; set; } public string Surname { get; set; } public DateTime Birthday { get; set; } public int Experience { get; set; } public virtual ICollection<CarOwner> CarOwners { get; set; } } public class Car { public int CarID { get; set; } public string Model { get; set; } public string Mark { get; set; } public string Type { get; set; } public int Price { get; set; } public string YearofRelease { get; set; } public virtual ICollection<CarOwner> CarOwners { get; set; } } public class CarOwner { public int CarOwnerID { get; set; } public int OwnerID { get; set; } public int CarID { get; set; } //public decimal? Grade { get; set; } public virtual Car Car { get; set; } public virtual Owner Owner { get; set; } } public class CarOwnersContext: DbContext { public CarOwnersContext():base("CarOwnersContext") { } public DbSet<Owner> Owners { get; set; } public DbSet<CarOwner> CarOwners { get; set; } public DbSet<Car> Cars { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); } } public class CarOwnerInit:DropCreateDatabaseIfModelChanges<CarOwnersContext> { protected override void Seed(CarOwnersContext context) { var owners = new List<Owner> { new Owner {Name="Sam", OwnerID=1, Surname="Lucky", Birthday=DateTime.Parse("1993-06-21"), Experience=3}, new Owner { Name="Nick", Surname="May", Birthday=DateTime.Parse("1994-04-06"), Experience=5 } }; owners.ForEach(s => context.Owners.Add(s)); context.SaveChanges(); var cars = new List<Car> { new Car {Model="gghguyg",CarID=2, Mark="ghffgy", Type="gghf", Price=7, YearofRelease="2001" }, new Car {Model="gghguyg",CarID=4, Mark="ghffgy", Type="gghf", Price=77, YearofRelease="2011" } }; cars.ForEach(s => context.Cars.Add(s)); context.SaveChanges(); var carowners = new List<CarOwner> { new CarOwner { OwnerID=1, CarID=2,CarOwnerID=1}, new CarOwner { OwnerID=2, CarID=4,CarOwnerID=2 } }; carowners.ForEach(s => context.CarOwners.Add(s)); context.SaveChanges(); } } Код для отображения подробностей о пользователе @model CarOwners.Models.Owner @{ ViewBag.Title = "Details"; } <h2>Details</h2> <div> <h4>Owner</h4> <hr /> <dl class="dl-horizontal"> <dt> @Html.DisplayNameFor(model => model.Name) </dt> <dd> @Html.DisplayFor(model => model.Name) </dd> <dt> @Html.DisplayNameFor(model => model.Surname) </dt> <dd> @Html.DisplayFor(model => model.Surname) </dd> <dt> @Html.DisplayNameFor(model => model.Birthday) </dt> <dd> @Html.DisplayFor(model => model.Birthday) </dd> <dt> @Html.DisplayNameFor(model => model.Experience) </dt> <dd> @Html.DisplayFor(model => model.Experience) </dd> <dt> @Html.DisplayNameFor(model => model.CarOwners) </dt> <dd> <table class="table"> <tr> <th>Course Title</th> <th>Grade</th> </tr> @foreach (var item in Model.CarOwners) { <tr> <td> @Html.DisplayFor(modelItem => item.Car.Mark) </td> <td> @Html.DisplayFor(modelItem => item.CarOwnerID) </td> </tr> } </table> </dd> </dl> </div> <p> @Html.ActionLink("Edit", "Edit", new { id = Model.OwnerID }) | @Html.ActionLink("Back to List", "Index") </p>