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

Kendo Grid Server Popup Edit - Checkbox List

6 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 17 Sep 2013, 01:01 PM
I am using a Kendo Grid in Server mode. I am using a popup editor for adding/editing records. The popup editor page has several text fields and checkbox list controls.

I am trying to use the checkboxlist control from mvccbl.com as below:


For examples see: http://mvccbl.com/Examples

@Html.CheckBoxListFor(x => x.PostedCities.CityIDs, // checkbox list name, 'PostedCities.CityIDs' in this case
x => x.AvailableCities, // List<City>()
x => x.Id, // City.Id
x => x.Name, // City.Name
x => x.SelectedCities) // List<City>() - should contain only cities to be selected

My requirement is that SelectedCities should be lazy loaded. So I am loading when the user clicks the Add/Edit button. Since there are several checkbox list controls on the editor page and all of them are required, so I am using data annotations [Required] on the posted values.  The problem is that if user forgets to check a box in one list and tries to update, model validation fails and that causes the popup editor to reload the data and thereby user selections are lost.

Any ideas on how to fix this?

Thanks

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 19 Sep 2013, 10:58 AM
Hello,

How are you loading the data on demand? Could you provide the code you are using? The checked state will not be preserved if the items are not populated from the ModelState on the server.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gary
Top achievements
Rank 1
answered on 19 Sep 2013, 12:08 PM
I am populating the properties when the user clicks edit, see

http://www.kendoui.com/forums/kendo-ui-complete-for-asp-net-mvc/grid/kendo-grid-server-popup-edit---load-properties-on-demand.aspx

0
Daniel
Telerik team
answered on 20 Sep 2013, 01:14 PM
Hi again,

The code in the forum thread that you provided does not show how the data is loaded and is used in your scenario. Could you provide the code that you are actually using? Also, when using server editing you could also check the parameter on the server and load the data when needed:

Request["Grid-mode"] != null
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gary
Top achievements
Rank 1
answered on 20 Sep 2013, 02:04 PM
I am calling a method on the Model to load the data.

I will try to create a simple project and upload it.
0
Gary
Top achievements
Rank 1
answered on 20 Sep 2013, 04:19 PM
Attached is a simple project that shows how data is being loaded
0
Accepted
Daniel
Telerik team
answered on 24 Sep 2013, 06:53 AM
Hi,

The selection is always determined based on the ID instead of the posted values, so the state will be lost. You should use the posted values instead when the form is posted to the update action. I attached the project modified to show how can this be achieved for the CustomerTypes.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Gary
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Gary
Top achievements
Rank 1
Share this question
or