我有组织的数据结构如下:
public class Organisation
{
public int OrganisationId { get; set; }
[Required]
public string OrganisationCode { get; set; }
[Required]
public string Name { get; set; }
public ICollection<OrganisationSite> Sites { get; set; }
public string TelNo { get; set; }
public int? AddressId { get; set; }
public Address Address { get; set; }
}
地址存储为&#39;自己的实体:
public class Address
{
public int AddressId { get; set; }
[Required]
public string HouseNoName { get; set; }
public string Street { get; set; }
public string Locality { get; set; }
public string TownCity { get; set; }
public string County { get; set; }
[Required]
[RegularExpression("^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$", ErrorMessage="Postcode must be recognisable UK postal code")]
public string Postcode { get; set; }
[Required]
public int AddressTypeId { get; set; }
public AddressType Type { get; set; }
}
地址将在一个应用程序的许多地方使用,所以听起来我需要一个部分视图,我可以重用?在我的OrganisationController中,我将前往我的OrganisationRepository并包含Address实体(实体框架):
public ActionResult Edit(int id = 1)
{
var organisation = _db.Organisation.Include("Address").Single(og => og.OrganisationId == id);
if (organisation == null)
{
return HttpNotFound();
}
return View(organisation);
}
如何在“组织编辑”视图中呈现部分地址视图?我有一个快速浏览并看到了对EditorTemplates的引用,这是我需要采取的方法,如果是这样,你知道任何体面的教程,因为我看到的那些看起来相当深?