Kendo Grid Server Popup Edit - Checkbox List

7 posts, 1 answers
  1. Gary
    Gary avatar
    7 posts
    Member since:
    Sep 2013

    Posted 17 Sep 2013 Link to this post

    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
  2. Daniel
    Admin
    Daniel avatar
    2231 posts

    Posted 19 Sep 2013 Link to this post

    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!
  3. Gary
    Gary avatar
    7 posts
    Member since:
    Sep 2013

    Posted 19 Sep 2013 Link to this post

    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

  4. Daniel
    Admin
    Daniel avatar
    2231 posts

    Posted 20 Sep 2013 Link to this post

    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!
  5. Gary
    Gary avatar
    7 posts
    Member since:
    Sep 2013

    Posted 20 Sep 2013 Link to this post

    I am calling a method on the Model to load the data.

    I will try to create a simple project and upload it.
  6. Gary
    Gary avatar
    7 posts
    Member since:
    Sep 2013

    Posted 20 Sep 2013 Link to this post

    Attached is a simple project that shows how data is being loaded
  7. Answer
    Daniel
    Admin
    Daniel avatar
    2231 posts

    Posted 24 Sep 2013 Link to this post

    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!
Back to Top