我需要一些关于如何最好地实现基于列表的局部视图并在页面上多次实现的建议。
所以鉴于此:
<div>
<b>Contact Name</b>
@Html.TextBoxFor(m => m.ApplicationDetail.Name, new { @class = "formInputSmall" })@Html.ValidationMessageFor(model => model.ApplicationDetail.Name)
<b>Current Address</b>
@Html.Partial("_address", Model.Address)
<b>Previous Address</b>
@Html.Partial("_address", Model.Address)
</div>
我有一个复杂的模型,它有一个标题记录并且可以包含多个地址。
模型页面类
public class EntityDetails
{
public ApplicationDetail ApplictaionDetails{ get; set; }
public List<Address> Address { get; set; }
}
地址部分
@model Application.Models.DataModels.Address
@Html.TextBoxFor(m => m.AddressLine1, new { @class = "formInputSmall" })@Html.ValidationMessageFor(model => model.AddressLine1)
@Html.TextBoxFor(m => m.AddressLine2, new { @class = "formInputSmall" })@Html.ValidationMessageFor(model => model.AddressLine2)
@Html.TextBoxFor(m => m.City, new { @class = "formInputSmall" })@Html.ValidationMessageFor(model => model.City)
@Html.TextBoxFor(m => m.Postcode, new { @class = "formInputSmall" })@Html.ValidationMessageFor(model => model.Postcode)
@Html.DropDownListFor(m => m.Country, new SelectList(ViewBag.CountryType, "ID", "Value"), "Select...", null)@Html.ValidationMessageFor(model => model.Country)
我不知道如何区分不同类型的地址,因为地址表包含不同的类型。
我能否就如何最好地实现我想要实现的目标提出一些建议。我不反对它被撕开。