【发布时间】:2021-08-20 22:52:06
【问题描述】:
我正在使用 ASP.NET MVC,我创建了两个模型类,User 和 Address。我想在同一个视图上使用它们,以允许用户在一页上输入所有信息。问题是 ASP.NET MVC 只允许传递一个模型。解决这种情况的最佳做法是什么?
public class Address
{
[Key]
public int Id { get; set; }
public int StreetNumber { get; set; }
public string Route { get; set;}
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
public string Coutry { get; set; }
public int Adresstype { get; set; }
public int UserId { get; set; }
public virtual User User { get; set; }
}
public class User
{
public User()
{
this.Ads = new HashSet<Ad>();
this.Addresses = new HashSet<Address>();
}
[Key]
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public int PhoneNumber { get; set; }
public virtual ICollection<Ad> Ads { get; set; }
public virtual ICollection<Address> Addresses { get; set;}
}
【问题讨论】:
标签: c# asp.net-mvc