DropDown returning all records instead of selected

3 posts, 0 answers
  1. Chris
    Chris avatar
    3 posts
    Member since:
    Jun 2017

    Posted 22 Jun 2017 Link to this post

    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. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1749 posts

    Posted 23 Jun 2017 Link to this post

    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.
  3. Chris
    Chris avatar
    3 posts
    Member since:
    Jun 2017

    Posted 23 Jun 2017 Link to this post

    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

Back to Top