1
我有問題試圖讓預選值工作。 我試過在SelectListItem中包含Selected,但它不會預先選擇。 任何線索,爲什麼它不匹配?謝謝你的幫助。DropDownListFor未選擇默認
RetailerId是int。 (它不是定義爲枚舉)
零售商是一個枚舉,例如:
public enum Retailer
{
Sears = 10,
Macys = 20
}
這裏是查看代碼:
@Html.DropDownListFor(x => x.RetailerId,
Enum.GetValues(typeof(Retailer)).Cast<Retailer>()
.OrderBy(o => o.GetDescription())
.Select(o => new SelectListItem() { Text = o.GetDescription(), Value = o.ToString(), Selected = (o.ToInt() == Model.RetailerId) }),
new { @data_placeholder = "Select Retailer", @class = "form-control" })
感謝你這麼很多,它的工作原理! thx的解釋!本來希望在裝訂時知道選定的財產在某些文件中是無用的。 – user1161137