How To Pass a list of objects into the create() ?!

2 posts, 0 answers
  1. K.Ramadan
    K.Ramadan avatar
    70 posts
    Member since:
    Feb 2020

    Posted 10 Jun Link to this post

    Hello,

    I'm trying to send selected values (from grid) but the creation is coming from the scheduler ..

    I saved the values in a global variable and i tried to this ..

     

    THIS is the ActionMethod in the Controller :

    public ActionResult Cal_Create ([DataSourceRequest]DataSourceRequest request, KommunikationViewModel kommunikation,string[] SIDMITARBEITER, string[] SIDPERSONEN, List<UserViewModel> MITARBEITER_OBJ)
            {}

     

     

    Create() method from my scheduler :

    .Create(create => create.Action("Cal_Create""Home").Data("pass_Einladung_Miatarbeiter_Personen"))

     

    PS : i copy pasted only the create() so that i don't need to copy my whole scheduler !

     

     

    This is the additional function that attached to the create() function :

     function pass_Einladung_Miatarbeiter_Personen() {
                    console.log("passing the array");
                    console.log(Global_Array_Grid_mitarbeiter_Selected);
                    var Mitarbeiter_Grids_IDs = new Array();
                    var Personen_Grids_IDs = new Array();
     
                    Global_Array_Grid_mitarbeiter_Selected.forEach(function (item, index) {
                        var SID_MITARBEITER_AUS_GLOBAL = item.Sid_mitarbeiter;
                        Mitarbeiter_Grids_IDs.push(SID_MITARBEITER_AUS_GLOBAL);
                    });
     
                    Global_Array_Grid_person_Selected.forEach(function (item, index) {
                        var SID_Personen_AUS_GLOBAL = item.Sid_personen;
                        Personen_Grids_IDs.push(SID_Personen_AUS_GLOBAL);
                    });
                    var xxoop = JSON.stringify(Global_Array_Grid_mitarbeiter_Selected);
                    return {
                        SIDMITARBEITER: Mitarbeiter_Grids_IDs,
                        SIDPERSONEN: Personen_Grids_IDs,
                        MITARBEITER_OBJ: xxoop}
                }

     

    // so i took one value from the object and put it into an array .. and that worked like a charm .. so defining a string[] as a parameter in the create ActionMethod .. did not make any problem .. but defining a List of object (like the code snippet) or a list of Objects .. is giving always NULL ! and it's not NULL because I'm console logging this variable in almost every step .. to follow if kendo delete the values after some action .. but no .. it's there .. but not getting sent to the ActionMethod ..

    Thanks in Advance ..

  2. Aleksandar
    Admin
    Aleksandar avatar
    186 posts

    Posted 12 Jun Link to this post

    Hello,

    Based on the provided details it appears the issue is related to the data serialization, but not actually to the passing of data vie the data handler function. However, the provided details are not enough to be certain what the issue might be caused by.

    If you inspect the Create action of the Scheduler you will notice that the data is passed to the action method as FormData. When using FormData it is not possible to append arrays and/or complex objects. You need to append key/value pairs for each property. Furthermore, when a list of objects is expected a particular naming convention needs to be followed. You can read more on passing complex objects and list of objects in the following SO thread:

    https://stackoverflow.com/questions/54736887/sending-multiple-json-lists-and-image-in-formdata-to-c-sharp

    Regards,
    Aleksandar
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top