Asp.net mvc 使用局部视图MVC创建编辑表单
我的组织数据结构如下:Asp.net mvc 使用局部视图MVC创建编辑表单,asp.net-mvc,asp.net-mvc-4,asp.net-mvc-partialview,mvc-editor-templates,Asp.net Mvc,Asp.net Mvc 4,Asp.net Mvc Partialview,Mvc Editor Templates,我的组织数据结构如下: public class Organisation { public int OrganisationId { get; set; } [Required] public string OrganisationCode { get; set; } [Required] public string Name { get; set; } public ICollection<OrganisationSite> Sit
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; }
}
地址将在许多地方使用,但考虑到一个应用程序,所以听起来我需要一个可以重用的局部视图?在我的OrganizationController中,我将访问我的OrganizationRepository,包括地址实体(实体框架):
如何在组织编辑视图中呈现部分地址视图?我快速浏览了一下,看到了EditorTemplates的参考资料,这是我需要采取的方法吗?如果是的话,你知道有什么像样的教程,因为我看到的那些看起来相当深入吗?请原谅我没有+1你的好建议。。。。。。。。根据您的请求加载部分视图的方法是通过jquery使用ajax调用。我的链接是一个谷歌搜索,上面有很多关于如何做到这一点的结果。如果你觉得没有帮助,我很抱歉
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; }
}
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);
}