I am doing experimental programming to get into ASP MVC.
I created a project for buildings containing rooms. A very simple attitude to many. I'm trying to get scaffolding to work, and from older MVC examples, it seems like this should work. However, the BuildingId field in Rooms does not map to the building model — there is no selection list in the view.
My models:
namespace BuildingManagement.Models
{
public class Building
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
public string Address { get; set; }
public string Street { get; set; }
public string City { get; set; }
public string Province { get; set; }
public string PostalCode { get; set; }
[Display(Name = "Phone")]
[DataType(DataType.PhoneNumber)]
[Required]
public string PhoneMain { get; set; }
[Display(Name = "Contact")]
[Required]
public string ContactName { get; set; }
public string Description { get; set; }
public virtual ICollection<Room> Rooms { get; set; }
}
}
and
namespace BuildingManagement.Models
{
public class Room
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
public string Type { get; set; }
public int BuildingId { get; set; }
}
}
I created a controller with views using the Entity Framework, it created forms, but not with the expected list of object selection in the room's editing view. Instead, it displays an entire input field.
What am I missing?