Kendo().DropDownListFor not updating, while Html.DropDownListFor does

3 posts, 1 answers
  1. Indicia
    Indicia avatar
    12 posts
    Member since:
    Mar 2012

    Posted 12 Nov 2014 Link to this post

    I have a situation, in which the Kendo().DropDownListFor isn't working as expected; I'm using a dropdown in a KendoGrid edit popup. The user is allowed to choose a user friendly value for a foreign key.

    This is working:

    @Html.DropDownListFor(m => m, new SelectList(ViewBag.Partners, "Id", "FriendlyName"), "Select Partner")

    But this is not:

    @(Html.Kendo().DropDownListFor(m => m)
        .BindTo(new SelectList(ViewBag.Partners, "Id", "FriendlyName"))
        .OptionLabel("Select Partner"))

    In both cases, the dropdown is displayed correctly, and the initial value is correctly selected.
    However, when saving, the Id field is cleared. When I look at the generated HTML markup, this is a part of it:

    <ul unselectable="on" class="k-list k-reset" tabindex="-1" role="listbox" aria-hidden="true" id="PartnerId_listbox" aria-live="off" style="overflow: auto; height: auto;"><li tabindex="-1" role="option" unselectable="on" class="k-item">Select Partner</li><li tabindex="-1" role="option" unselectable="on" class="k-item">Indicia Test SFTP</li><li tabindex="-1" role="option" unselectable="on" class="k-item">Indicia Test Mail</li><li tabindex="-1" role="option" unselectable="on" class="k-item">Indicia Test FS</li><li tabindex="-1" role="option" unselectable="on" class="k-item k-state-selected k-state-focused" id="PartnerId_option_selected" aria-selected="true">Test Jesse</li></ul>

    As you can see, no Id's are in the markup, which I find suspicious.

    Here is how the ViewBag.Partners value is populated (in the controller):
    /// <summary>
    /// Populates the partners.
    /// </summary>
    protected void PopulatePartners()
    {
        ViewBag.Partners = Database.Partners.Select(pg => new { pg.Id, pg.FriendlyName }).ToArray();
    }

    What is going on here? Why is the normal Html.DropDownListFor working, while Kendo's version isn't?
  2. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 14 Nov 2014 Link to this post

    Hello ICT,

    The html of the rendered popup is expected. Widget renders a un-ordered list of LI elements for text values (defined via DataTextField) in the data source (defined in this case with BindTo method). The selected value is persisted in a hidden input element. 

    In order to continue with our investigation I will need a small runnable demo. It will help to observe the erroneous behavior and help you much faster.

    Best regards,
    Georgi Krustev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Indicia
    Indicia avatar
    12 posts
    Member since:
    Mar 2012

    Posted 18 Dec 2014 Link to this post

    I have fixed this eventually by adding .ValuePrimitive(true) to the DropDownListFor() line.
Back to Top