I'm trying to use KendoUI DropDownListFor for my model foreignkey and bind it with ViewData/ViewBag complete list but can't seems to work, am i missing something?
@(Html.DropDownListFor(model => model.Hotel.HotelStatusId, ViewData["HotelStatuses"] as SelectList))
This seems to work but required me to create a viewmodel.
@(Html.Kendo().DropDownListFor(model => model.Hotel.HotelStatusId)
.BindTo(Model.HotelStatuses)
.OptionLabel("select hotel status...")
)
I'm avoiding using viewmodel because i need to submit the data back to ASP MVC. With the custom viewmodel, i couldn't bind it correctly.
Viewbag/ViewData can be filled like this in controller:
ViewData["HotelStatuses"] =
new SelectList(db.HotelStatuses, "HotelStatusId", "HotelStatusText");
And in view you can use ViewData/ViewBag:
@(Html.Kendo().DropDownListFor(model => model.Hotel.HotelStatusId)
.BindTo(ViewData["HotelStatuses"] as SelectList))
.DataTextField("Text")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With