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

DropDown returning all records instead of selected

2 Answers 71 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 22 Jun 2017, 08:36 AM

I have a dropdown list that populates from a users table, this populates correctly and then using the DropdownListFor I wish to bind it to the corresponding field in my model (using MVC). It returns all of the records inside the DropDownList and causes a Json error. Any ideas?

cshtml:

 @Html.LabelFor(model => model.AccountAdminUserID, htmlAttributes: new { @class = "control-label" })
                    @(Html.Kendo().DropDownListFor(model => model.AccountAdminUserID)
                    .Name("AccManagersDropDownList")
                    .DataTextField("FullName")
                    .DataValueField("AdminUserID")
                    .HtmlAttributes(new { style = "width: 100%" })
                    .DataSource(source =>
                {
                    source.Read(read =>
                {
                    read.Action("GetAccManagers", "AccountManager");
                })
                .ServerFiltering(true);
            })
            .SelectedIndex(0)
                    )

 

 

2 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 23 Jun 2017, 02:38 PM
Hello Chris,

We would first recommend removing the Name declaration, when bound to a model the DropDownList gets its name from the field it is bound to (AccountAdminUserID), and you can also check whether the json response is in the expected format. It should look something like this:
[{"FullName":"Anna","AdminUserID":1},{"FullName":"Bob","AdminUserID":2}]

Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Chris
Top achievements
Rank 1
answered on 23 Jun 2017, 02:41 PM

Yes, realised this was the issue. 
Thanks for your response. I have another query regarding The Editor component when being used inside a TabStrip of a grid. Will post shortly. 

Regards,

Chris

Tags
DropDownList
Asked by
Chris
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or