型號的DropDownList的SelectedItem不工作(剃刀ASP MVC5)
public class MyModel {
public string ItemXYZ { get; set; }
}
控制器
public ActionResult Edit(int? id)
{
var x = db.XYZs.Find(id);
ViewBag.Item_XYZ = new SelectList(new[] { "X", "Y", "Z"}, x.CurrentXYZ);
}
查看
@Html.DropDownList("XYZ123", @ViewBag.Item_XYZ as SelectList, new { @class = "special-class" })
問題
如果我將我的DropDownList更改爲mach設置在我的模型中的名稱,則所選值不起作用。
@Html.DropDownList("ItemXYZ" ....)
如果我ViewBag
項目的名稱匹配,SelectedItem
不起作用。
@Html.DropDownList("Item_XYZ" ....)
但是,如果我追加123
(例如),SelectedItem
工作得很好。
UPDATE
This is the same issue我有,但我不明白爲什麼或如何處理我的控制器的回報嗎?
另外,如何訪問「XYZ123」的發佈值,因爲它不與我的控制器中的模型綁定在一起? – syllogistic