3 回答

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
您應(yīng)該這樣做:
@Html.DropDownListFor(m => m.ContribType,
new SelectList(Model.ContribTypeOptions,
"ContribId", "Value"))
哪里:
m => m.ContribType
是結(jié)果值所在的屬性。

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超4個(gè)贊
我認(rèn)為這會有所幫助:在Controller中獲取列表項(xiàng)和選定的值
public ActionResult Edit(int id)
{
ItemsStore item = itemStoreRepository.FindById(id);
ViewBag.CategoryId = new SelectList(categoryRepository.Query().Get(),
"Id", "Name",item.CategoryId);
// ViewBag to pass values to View and SelectList
//(get list of items,valuefield,textfield,selectedValue)
return View(item);
}
并在視野中
@Html.DropDownList("CategoryId",String.Empty)

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
要將動(dòng)態(tài)數(shù)據(jù)綁定到DropDownList中,可以執(zhí)行以下操作:
如下所示在Controller中創(chuàng)建ViewBag
ViewBag.ContribTypeOptions = yourFunctionValue();
現(xiàn)在在如下所示的視圖中使用該值:
@Html.DropDownListFor(m => m.ContribType,
new SelectList(@ViewBag.ContribTypeOptions, "ContribId",
"Value", Model.ContribTypeOptions.First().ContribId),
"Select, please")
- 3 回答
- 0 關(guān)注
- 423 瀏覽
添加回答
舉報(bào)