There is problem with Cascading ComboBox in edit mode. When using for inserting new record – it’s working fine, allowing to choose City and then district in the city selected. When opening record for edit, then Child-ComboBoxFor is empty, although it has value assigned.
It seems that during initialization, Parent-ComboBoxFor reinitializing Child-ComboBoxFor and value is cleared. How to keep value during Edit?
I found some articles that similar issue was fixed in 2012 version and we are using latest version of Kendo UI for MVC.
Code sample is provided below.
Code for Parent-ComboBoxFor:
@(Html.Kendo().ComboBoxFor(model => model.CityId)
.HtmlAttributes(new { id = Html.IdFor(m => m.CityId).ToString() })
.DataTextField("CityName")
.DataValueField("CityId")
.Filter(FilterType.Contains)
.DataSource(source =>
{
source.Read(read =>
{
read.Action(MVC.Object.ActionNames.Cities_Read, MVC.Object.Name);
});
})
)
Code for Child-ComboBoxFor:
@(Html.Kendo().ComboBoxFor(model => model.CityAreaId)
.HtmlAttributes(new { id = Html.IdFor(m => m.CityAreaId).ToString() })
.Placeholder("Choose area...")
.DataTextField("Name")
.DataValueField("Id")
.Filter(FilterType.Contains)
.DataSource(source =>
{
source.Read(read =>
{
read.Action(MVC.Object.ActionNames.GetCascadeCityAreas, MVC.Object.Name).Data("filterCityAreas");
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom(Html.IdFor(m => m.CityId).ToString())
)<script>
function filterCityAreas() {
return {
cityId: $("#@Html.IdFor(m => m.CityId)").val(),
cityAreasFilter: $("#@Html.IdFor(m => m.CityAreaId)").data("kendoComboBox").input.val()
};
}
</script>
It seems that during initialization, Parent-ComboBoxFor reinitializing Child-ComboBoxFor and value is cleared. How to keep value during Edit?
I found some articles that similar issue was fixed in 2012 version and we are using latest version of Kendo UI for MVC.
Code sample is provided below.
Code for Parent-ComboBoxFor:
@(Html.Kendo().ComboBoxFor(model => model.CityId)
.HtmlAttributes(new { id = Html.IdFor(m => m.CityId).ToString() })
.DataTextField("CityName")
.DataValueField("CityId")
.Filter(FilterType.Contains)
.DataSource(source =>
{
source.Read(read =>
{
read.Action(MVC.Object.ActionNames.Cities_Read, MVC.Object.Name);
});
})
)
Code for Child-ComboBoxFor:
@(Html.Kendo().ComboBoxFor(model => model.CityAreaId)
.HtmlAttributes(new { id = Html.IdFor(m => m.CityAreaId).ToString() })
.Placeholder("Choose area...")
.DataTextField("Name")
.DataValueField("Id")
.Filter(FilterType.Contains)
.DataSource(source =>
{
source.Read(read =>
{
read.Action(MVC.Object.ActionNames.GetCascadeCityAreas, MVC.Object.Name).Data("filterCityAreas");
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom(Html.IdFor(m => m.CityId).ToString())
)<script>
function filterCityAreas() {
return {
cityId: $("#@Html.IdFor(m => m.CityId)").val(),
cityAreasFilter: $("#@Html.IdFor(m => m.CityAreaId)").data("kendoComboBox").input.val()
};
}
</script>