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:
But this is not:
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:
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):
What is going on here? Why is the normal Html.DropDownListFor working, while Kendo's version isn't?
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?