Reputation: 1502
I'm trying to populate a dropdownlist for use in my Kendo Grid using Editor Templates.
My StatesEditor.cshtml contains:
@(Html.Kendo().DropDownList()
.Name("State")
.DataValueField("StateID")
.DataTextField("ShortName")
.BindTo((System.Collections.IEnumerable)ViewData["states"]))
In my Controller I have:
public ActionResult Index()
{
var db = new ACoreEntities();
db.Configuration.ProxyCreationEnabled = false;
var states = db.StateLookups;
var stateList = states.Select(state => state.ShortName);
ViewData["states"] = stateList;
return View("~/Views/System/PMarkup/Index.cshtml");
}
In my actual grid, when I click the 'Edit' button for the row I get a dropdownlist that contains 51 'undefined' entries.
Upvotes: 0
Views: 1165
Reputation: 1502
I ended up creating a State model then in my ActionResult I changed my code to:
ViewData["states"] = new ACoreEntities()
.StateLookups
.Select(s => new State
{
Id = s.StateID,
ShortName = s.ShortName
})
.OrderBy(s => s.ShortName);
Upvotes: 1