Razor 在HTTP POST上解析DropdownListFor(m=>;ListDictionary[key])时出现问题

Razor 在HTTP POST上解析DropdownListFor(m=>;ListDictionary[key])时出现问题,razor,http-post,html.dropdownlistfor,Razor,Http Post,Html.dropdownlistfor,我有一个视图模型属性来保存下拉选择值列表,如: private ListDictionary _claimDropdownValueCollection = new ListDictionary(); public ListDictionary ClaimDropdownValueCollection { get { return _claimDropdownValueCollection; } set { _claimDropdownValueCollection = value; }

我有一个视图模型属性来保存下拉选择值列表,如:

  private ListDictionary _claimDropdownValueCollection = new ListDictionary();
  public ListDictionary ClaimDropdownValueCollection { get { return _claimDropdownValueCollection; } set { _claimDropdownValueCollection = value; } }
在执行GET时,我也在我的视图模型中循环一个不同的ListDictionary,其中包含“dropdown type”名称:

这是4个下拉列表,其中有键1,2,3,4(为了我的示例,我的键会更复杂,这里是简单的键),四个中有三个有选择,所以我传回所选ID的2,5和11

但问题是,当我在接收发布数据的[HttpPost]控制器方法中调试时,我无法将此数据作为视图模型listdictionary对象的一部分。这将显示“ClaimDropdownValueCollection”属性为空

我希望能够说出这样的话:

foreach (DictionaryEntry de in vm.ClaimDropdownValueCollection) {
//do something here with de.Key and de.Value                        
                    }

那么我在RAZOR代码中做错了什么?。。。救命啊

问题在于HTML助手以及我是如何发回的。以下是我解决问题的方法(多亏了我的首席技术官!)

已创建“我的视图模型”属性,该属性将用作要从中填充的资源:

Dictionary<int, List<SelectListItem>> CCSetting_ClaimDropdownTypeCollection
字典CCSetting\u ClaimDropdownTypeCollection
创建了另一个具有相同键的词典,其值将为用户选择:

Dictionary<int, int> ClaimDropdownValueCollection
Dictionary ClaimDropdownValueCollection
现在在剃刀方面,我正在做类似的事情(注意使用HTML.Hidden和HTML.Dropdown代替HTML.DropdownFor):

@foreach(Model.CCSetting\u ClaimDropdownTypeCollection中的变量de){
@Html.Hidden(“ClaimDropdownValueCollection[“+@de.Key+”],@de.Key)
@Html.DropDownList(“ClaimDropdownValueCollection[“+@de.Value+”],@de.Value,new{@class=“chzn select”,@data\u placeholder=“Choose an option…”,@style=“width:350px;”
}
对不起,我没有用更好的方式来表达我的问题。也许,我可能是在几个小时的沮丧之后才发帖的,结果在措辞上做得不好。获得这个问题的“风滚草”徽章促使我回来发布解决方案。好吧,就这样结束吧,希望有一天会有人碰到这个

Dictionary<int, List<SelectListItem>> CCSetting_ClaimDropdownTypeCollection
Dictionary<int, int> ClaimDropdownValueCollection
@foreach (var de in Model.CCSetting_ClaimDropdownTypeCollection) {
                        <div class="formRow">
                                                            <div class="formRight searchDrop">
@Html.Hidden("ClaimDropdownValueCollection[" + @de.Key + "]", @de.Key)
                                @Html.DropDownList("ClaimDropdownValueCollection[" +  @de.Value + "]", @de.Value, new { @class = "chzn-select", @data_placeholder="Choose an option...", @style="width: 350px;" })
                            </div>
                            <div class="clear"></div>
                        </div>
                    }