我想設置從我的下拉列表中選擇的值從模型值。 有人可以幫助我在這裏設置模型的值來選擇。MVC下拉列表集合選擇
@foreach (var item in Model)
{
<p>
@Html.DisplayFor(modelItem => item.Type)
</p>
<p>
@Html.DropDownList("categoryvalues", (IEnumerable<SelectListItem>)ViewBag.Category, "Select")
</p>
}
嘗試以下
@Html.DropDownListFor(modelItem => item.Type, new SelectList((IEnumerable<SelectListItem>)ViewBag.Category,"Value","Text",modelItem => item.Type.ToString()))
我收到錯誤
無法轉換lambda表達式鍵入「對象」,因爲它不是一個委託類型
你能告訴我們你的模型傳遞給視圖? – Kaf