我正在尝试通过向 Chef 添加电话号码来扩展 ProDinner。
ChefInput 视图模型:
public class ChefInput :Input { public string Name { get; set; } public ChefInput() { PhoneNumberInputs = new List<PhoneNumberInput>(){ new PhoneNumberInput() };} public IList<PhoneNumberInput> PhoneNumberInputs { get; set; } }
PhoneInput 视图模型:
public class PhoneNumberInput :Input { public string Number { get; set; } public PhoneType PhoneType { get; set; } <-- an enum in Core project }
厨师 Create.cshtml 文件:
@using (Html.BeginForm()) { @Html.TextBoxFor(o => o.Name) @Html.EditorFor(o => o.PhoneNumberInputs) }
EditorTemplate 文件夹中的 PhoneNumberInput.cshtml:
@using (Html.BeginCollectionItem("PhoneNumberInputs")) { @Html.DropDownListFor(m => m, new SelectList(Enum.GetNames(typeof(PreDefPhoneType)))) @Html.TextBoxFor(m => m.Number) }
调试时,我在 Crudere 文件中的 Create 处停止它,Phone 集合为空。
有人有想法么?提前致谢。