好的,我有以下代码
#region getDurationListDD
private List<KeyValuePair<int, int>> getDurationListDD
{
get
{
List<KeyValuePair<int, int>> dDur = new List<KeyValuePair<int, int>>();
dDur.Add(new KeyValuePair<int, int>(2, 2));
dDur.Add(new KeyValuePair<int, int>(3, 3));
dDur.Add(new KeyValuePair<int, int>(4, 4));
dDur.Add(new KeyValuePair<int, int>(7, 7));
dDur.Add(new KeyValuePair<int, int>(14, 14));
dDur.Add(new KeyValuePair<int, int>(21, 21));
return dDur;
}
}
#endregion
然后在主ActionResult中进行以下操作......
ViewData["changeDuration"] = new SelectList(getDurationListDD, "Key", "Value", Duration);
这在视图上
Html.DropDownList("changeduration", (SelectList)ViewData["changeDuration"])
现在如果设置了持续时间(即int Duration = 7;)那么我会期望选择7,但由于某种原因它不是。在我放弃尝试并做更有成效的事情之前的任何暗示?
TA
答案 0 :(得分:3)
修好它。
更改:
Html.DropDownList("changeduration", (SelectList)ViewData["changeDuration"])
要:
Html.DropDownList("cduration", (SelectList)ViewData["changeDuration"])
解决问题