我正在尝试使用 KendoUI DropDownListFor 作为我的模型外键并将其与 ViewData/ViewBag 完整列表绑定(bind),但似乎无法工作,我是否缺少某些内容?
@(Html.DropDownListFor(model => model.Hotel.HotelStatusId, ViewData["HotelStatuses"] as SelectList))
这似乎可行,但需要我创建一个 View 模型。
@(Html.Kendo().DropDownListFor(model => model.Hotel.HotelStatusId)
.BindTo(Model.HotelStatuses)
.OptionLabel("select hotel status...")
)
我避免使用 View 模型,因为我需要将数据提交回 ASP MVC。使用自定义 View 模型,我无法正确绑定(bind)它。
最佳答案
Viewbag/ViewData可以在 Controller 中这样填充:
ViewData["HotelStatuses"] =
new SelectList(db.HotelStatuses, "HotelStatusId", "HotelStatusText");
在 View 中你可以使用ViewData/ViewBag:
@(Html.Kendo().DropDownListFor(model => model.Hotel.HotelStatusId)
.BindTo(ViewData["HotelStatuses"] as SelectList))
.DataTextField("Text")
关于asp.net-mvc - 如何将 KendoUI DropDownListFor 绑定(bind)到 ViewData 或 ViewBag?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14108019/