Bind DropDownList to action?

1 posts, 0 answers
  1. Max
    Max avatar
    1 posts
    Member since:
    Jul 2012

    Posted 07 Aug 2012 Link to this post

    Hello,

    I have an Editor Template in which only a DropDownList is present. I am trying to populate that DropDownList using an action on my controller. I have the following code:

    @(Html.Kendo().DropDownListFor(m => m)
                    .DataSource(
                        datasource => datasource
                            .Read(r => r.Action("GetPossibleLines", "ProductionProgram"))
                            .ServerFiltering(true)
                        )
                    .DataTextField("Text")
                    .DataValueField("Value")
                    .HtmlAttributes(new { style = "width: 200px" }))

    My action looks like this:

    [HttpPost]
    public ActionResult GetPossibleLines()
    {
        var options =
            new List<SelectListItem>()
            {
                new SelectListItem() { Text = "LI50", Value = "51" }
            };
     
        return Json(options);
    }

    What am I doing wrong? The DropDownList doesn't get filled and keeps loading forever.
Back to Top