我在视图中有以下动态创建的文本框:
@for (int i = 0; i < Model.MullionList.Count; i++)
{
ItemDrops curMullItem = Model.MullionList.ElementAt(i);
<div class="form-group">
@Html.Label(curMullItem.ItemName.ToString(), new { @class = "col-sm-6 control-label" })
<div class="col-sm-6">
@Html.TextBoxFor(x => x.MullionList[i].ItemPossInfo, new { @class = "form-control" })
@Html.HiddenFor(x => x.MullionList[i].ItemName)
</div>
</div>
}
我偶然注意到某些类型的产品在发布时(对于MullionList)返回null,即使我选择了这些下拉列表。
因此它适用于某些产品,但不适用于其他产品。
甚至更奇怪的部分是当我在视图中进一步向下移除此部分时(即表格发布时MulionList不为空)
<div class="form-group">
@Html.Label("Glass", new { @class = "col-sm-6 control-label", id = "glass-first-label" })
<div class="col-sm-6">
@Html.DropDownListFor(gu => gu.GlassItems[0].Value, Model.GlassTypes, "-- Select --", new { @class = "form-control glass-multi-select", id = "Glass" + 0 })
</div>
</div>
<div id="hidden-glass-select" style="display: none">
@for (int i = 1; i < Model.GlassUnitsCount; i++)
{
var glassUnit = Model.GlassUnits.ElementAt(i);
<div class="form-group">
@Html.Label(glassUnit.ToString(), new { @class = "col-sm-6 control-label" })
<div class="col-sm-6">
@Html.DropDownListFor(gu => gu.GlassItems[i].Value, Model.GlassTypes, "-- Select --", new { @class = "form-control glass-multi-select", id = "Glass" + i })
</div>
</div>
}
</div>
<div class="form-group">
@Html.LabelFor(go => go.GlazzingInfoVal, "Glazzing Option", new { @class = "col-sm-6 control-label" })
<div class="col-sm-6">
@Html.DropDownListFor(go => go.GlazzingInfoVal, Model.GlazzingOptions, "-- Select --", new { @class = "form-control" })
</div>
</div>
答案 0 :(得分:0)
我想我现在已经解决了这个问题。
我重命名了所有项目(以Glass或Glazzing开头的列表,它可以工作!)
这看起来像是一个合适的MVC错误
感谢您的回答:https://stackoverflow.com/a/16113919/66975
这花了我几个小时,GRRRR