我对此进行了一些研究,似乎发现了一些过时的帖子,或者在我的情况下不太适用。我可能在搜索时使用了错误的关键字... =/
在我的网页上,我有包含组框的选项卡,其中包含行,而行又包含项目。所以它是 4 级列表的列表。
问题:
回发时, ViewModel.Tabs 为空,我无法保存任何内容。一切都很好地显示,但没有任何东西被发回。
编码
视图/共享/EditorTemplates/Tab.cshtml
@model AWMCCRM.Web.ViewModels.Tab
@Html.HiddenFor(vm => vm.Name)
<div id="tab-@Model.Name.Replace(" ", string.Empty)" class="tab-content two">
@Html.EditorFor(vm => vm.Groups)
</div>
视图/共享/EditorTemplates/Group.cshtml
@model AWMCCRM.Web.ViewModels.Group
@Html.HiddenFor(vm => vm.Name)
<fieldset>
<legend>@Model.Name</legend>
@Html.EditorFor(vm => vm.Lines)
</fieldset>
视图/共享/EditorTemplates/Line.cshtml
@model AWMCCRM.Web.ViewModels.Line
<div class="_100Max">
@Html.HiddenFor(vm => vm.Name)
@Html.EditorFor(vm => vm.Items)
</div>
视图/共享/EditorTemplates/Item.cshtml
@model AWMCCRM.Web.ViewModels.Item
<div class="_@Model.DisplaySize" title="@Model.Description">
<p>
@Html.HiddenFor(x => x.DataType)
@Html.HiddenFor(x => x.Description)
@Html.HiddenFor(x => x.DisplaySize)
@Html.HiddenFor(x => x.DisplayType)
@Html.HiddenFor(x => x.IDsPiped)
@Html.HiddenFor(x => x.ItemType)
@Html.HiddenFor(x => x.Name)
@Html.LabelFor(vm => vm.Value, Model.Name)
@switch (Model.DisplayType.ToLower().Replace(" ", string.Empty))
{
case "checkbox":
@Html.CheckBoxFor(vm => Convert.ToBoolean(vm.Value))
break;
case "dropdownlist":
@Html.DropDownListFor(vm => vm.Value, Model.ValueOptionListItems)
break;
case "multiselectlist":
@Html.ListBoxFor(
x => x.SelectedValueList,
Model.ValueOptionListItems,
new { id = "itemValuesMultiSelect", multiple = "multiple", Size = 15 })
break;
case "radiobutton":
@Html.RadioButtonFor(vm => vm.Value, Model.Value)
break;
case "textarea":
@Html.TextAreaFor(vm => vm.Value)
break;
default:
@Html.TextBoxFor(vm => vm.Value)
break;
}
</p>
</div>
ViewModel(精简版)
namespace AWMCCRM.Web.ViewModels
{
public class PersonEditViewModel
{
public List<Tab> Tabs { get; set; }
//Other properties
//...
}
}
观点(精简版)
@using (Html.BeginForm("Edit", "Person", FormMethod.Post, new { id = "validate-form", @class = "block-content form" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(x => x.PersonID)
@foreach (var tab in Model.Tabs)
{
@Html.EditorFor(vm => tab)
}
<input class="close-toolbox button" type="submit" value="Save">
}
有什么建议么?
谢谢