【发布时间】:2020-03-24 02:01:31
【问题描述】:
型号:
public string FreeText { get; set; }
public Dictionary<int, string> SearchValues { get; set; }
public List<DropDownModel> DropDowns { get; set; }
查看:
@using (Html.BeginForm("GetSearchResults", "Home", FormMethod.Post))
{
@Html.TextBoxFor(m => m.FreeText, new { @class = "form-control mb-3", @placeholder = "Search..." })
foreach (var dropDown in Model.DropDowns)
{
@Html.DropDownListFor(m => m.SearchValues[dropDown.DataFieldId], dropDown.ListItems, dropDown.OptionLabel, new { @class = "form-control mb-3" });
}
<button type="submit" class="btn btn-primary btn-block">Search</button>
}
FreeText 输入字段的传递非常好。但即使 SearchValues 字段的下拉列表在页面上正确显示,它在控制器中仍返回为空 (Count = 0)。这是为什么,我可以将字典传递给控制器吗?
【问题讨论】:
-
您正在尝试将下拉字段 ID 保存为 int 并将下拉值保存为字符串是否正确?
-
@JerdineSabio 是的,100% 正确。
标签: asp.net-mvc razor