This is a migrated thread and some comments may be shown as answers.

Bind DropDownList to action?

0 Answers 47 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 07 Aug 2012, 05:03 AM
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.

No answers yet. Maybe you can help?

Tags
DropDownList
Asked by
Max
Top achievements
Rank 1
Share this question
or