与MVC发布列表奇怪的行为 [英] Strange behaviour with MVC posting list

查看:124
本文介绍了与MVC发布列表奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的看法如下动态创建文本框:

  @for(INT I = 0; I< Model.MullionList.Count;我++)
{
    ItemDrops curMullItem = Model.MullionList.ElementAt(ⅰ);
    < D​​IV CLASS =表单组>
        @ Html.Label(curMullItem.ItemName.ToString(),新的{@class =COL-SM-6控制标签})        < D​​IV CLASS =COL-SM-6>
            @ Html.TextBoxFor(X => x.MullionList [I] .ItemPossInfo,新{@class =表格控})
            @ Html.HiddenFor(X => x.MullionList [I] .ItemName)
        < / DIV>
    < / DIV>
}

我occaionally注意到了某些类型的产品发布时(对于MullionList)这是返回null的,即使我选择了这些下拉菜单。

所以它适用于特定的产品,而不是其他。

更加古怪的部分是,当我进一步去除这部分下来它的工作原理图(当窗体发布即MulionList不为null)

 < D​​IV CLASS =表单组>
    @ Html.Label(玻璃,新{@class =COL-SM-6控制标签ID =玻璃第一标签})
    < D​​IV CLASS =COL-SM-6>
        @ Html.DropDownListFor(区=> gu.GlassItems [0] .value的,Model.GlassTypes - 选择 - 新{@class =表格控玻璃多选ID =玻璃+ 0})
    < / DIV>
< / DIV>< D​​IV ID =隐玻璃选择的风格=显示:无>
    @for(INT I = 1; I< Model.GlassUnitsCount;我++)
    {
        变种glassUnit = Model.GlassUnits.ElementAt(ⅰ);
        < D​​IV CLASS =表单组>
            @ Html.Label(glassUnit.ToString(),新的{@class =COL-SM-6控制标签})
            < D​​IV CLASS =COL-SM-6>
                @ Html.DropDownListFor(区=> gu.GlassItems [I] .value的,Model.GlassTypes - 选择 - 新{@class =表格控玻璃多选ID =玻璃+ I})
            < / DIV>
        < / DIV>    }
< / DIV>< D​​IV CLASS =表单组>
    @ Html.LabelFor(去=> go.GlazzingInfoVal,Glazzing选项,新{@class =COL-SM-6控制标签})
    < D​​IV CLASS =COL-SM-6>
        @ Html.DropDownListFor(去=> go.GlazzingInfoVal,Model.GlazzingOptions - 选择 - 新{@class =表格控})
    < / DIV>
< / DIV>


解决方案

我想我现在已经解决了这个问题。

我改名的所有项目(与玻璃或Glazzing启动列表和它的作品!)

这看起来像一个合适的MVC错误

由于这样的回答: http://stackoverflow.com/a/16113919/66975

这已经成本核算好几个小时,GRRRR

I have the following dynamically created textboxes in my view:

 @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>                                
}

I noticed occaionally for certain types of product this was returning null when posted (for MullionList), even though i selected these dropdowns.

so it works for certain product but not others.

The even weirder part is when i remove this section further down the view it works (ie MulionList is not null when the form is posted)

 <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> 

解决方案

I think I have fixed this now.

I renamed all items (lists that started with Glass or Glazzing and it works!)

This looks like a proper MVC bug

Thanks to this answer:http://stackoverflow.com/a/16113919/66975

This has costed me several hours, GRRRR

这篇关于与MVC发布列表奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆