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

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

2 Answers 544 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Indicia
Top achievements
Rank 1
Indicia asked on 12 Nov 2014, 12:23 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 14 Nov 2014, 08:50 AM
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.

 
0
Indicia
Top achievements
Rank 1
answered on 18 Dec 2014, 10:54 AM
I have fixed this eventually by adding .ValuePrimitive(true) to the DropDownListFor() line.
Tags
DropDownList
Asked by
Indicia
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Indicia
Top achievements
Rank 1
Share this question
or