Kendoui dropdownlist binding to a datasource

When setting the datasource of the dropdownlist, make sure the function that provides the list returns a JsonResult. I was having issues because I was binding to a List<item> and then tried IEnumerable<item>.  I had to change the function to return a Json result version of that Ienumerable as follows:

public JsonResult GetJsonGroupList()
{
return Json(Groups, JsonRequestBehavior.AllowGet);

//Groups is  a List object
}

The razor syntax is:

@(Html.Kendo().DropDownList()
.Name(“Goal.GroupId”)
.HtmlAttributes(new {style = “width:250px”})
.DataTextField(“Product_Group_Description”)
.DataValueField(“Product_Group_Code”)
.DataSource(source =>
{
source.Read(read =>
{
read.Action(“GetJsonGroupList”, “Goal”);
});
})
)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s