We've got a drop down list inside a pop-up template from a grid. This drop down list is being populated correctly and you can select a value from the list and the value will be sent to the controller correctly. However when the data is loaded no value is selected initially so we are calling the select(0) function to automatically select the first item in the list. But when we do this the id value is not passed to the controller if the user doesn't select another item from the list.
Below is the DropDownList control. We are using the DataBound event to set the default value.
@(Html.Kendo().DropDownList()
.Name(
"ParentId"
)
.DataSource(ds => ds
.Custom()
.Transport(tr => tr
.Read(read => read.Action(
"OHGetGroupsForDropDown"
,
"Groups"
)))
.Schema(sc => sc.Data(
"Data"
).Total(
"Total"
).Errors(
"errors"
)))
.DataValueField(
"Id"
)
.DataTextField(
"Name"
)
.Filter(FilterType.Contains)
.Events(e => e.DataBound(
"parentIdDefaults"
))
.HtmlAttributes(
new
{@style =
"width:100%"
, data_value_primitive =
"true"
}))
Below is the DataBound() event code. We are simply selecting the first item in the list.
function
parentIdDefaults(e) {
var
dropdownlist = $(
"#ParentId"
).data(
"kendoDropDownList"
);
dropdownlist.select(0);
}
The above code works visually but if we do not select another item in the drop down list the ParentId value of the object passed to the controller is 0. If we select another item in the list the ParentId value passed to the controller is correct.
Does anyone know why the select() call is not fully selecting the drop down list item but only appears to?