scheduler binding/ajax issues

7 posts, 1 answers
  1. chris
    chris avatar
    19 posts
    Member since:
    Jan 2013

    Posted 23 Dec 2013 Link to this post

    I'm attempting to use a custom editor template in a kendo scheduler but have 2 issues.  

    1.  I have a mutliselect in the editor template, and am unable to get the selected options to bind and be posted to the server.
    2.  My ajax requests are wonky.  
      2a.  What I'm seeing is when i click save it fires the datasource.create method multiple times (sometimes twice sometimes 3 times) and posts the same data to the server.
      2b.  When i attempt to delete an event the datasource.create endpoint is hit and not the datasource.destroy method.


    I've attached a solution with an example.  I've neven used these custom editor templates before so i think its likely im not binding it properly.

    Thanks,
    Chris
      
  2. chris
    chris avatar
    19 posts
    Member since:
    Jan 2013

    Posted 23 Dec 2013 Link to this post

    deleting this post, i was able to upload an example.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 25 Dec 2013 Link to this post

    Hello Chris,

    When sending projects to support staff, it is recommended to make sure they are configured correctly and runnable without the need to makes fixes and adjustments, for example (in this case) adding missing script files, removing duplicate registrations of Kendo UI scripts and replacing mismatched Kendo UI assembly reference. Thank you for understanding.

    The Create action will be called only once, and the Destroy action will be called as expected if you define the Model and its ID in the DataSource configuration, as demonstrated at

    http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/scheduler/ajax-editing

    and in our demos, in which the Scheduler uses Ajax binding.

    Regards,
    Dimo
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. chris
    chris avatar
    19 posts
    Member since:
    Jan 2013

    Posted 26 Dec 2013 Link to this post

    Thanks Dimo,

    I didn't realizing defining my model was required in the helper when i specified the type in the helpers definition.  I will define the model.  This doesn't address my other issue though which is how to i incorporate a multiselect in the editor template and have the selected values sent properly to the server?  If you notice my class OutageEvent has a list<string> called LocationIds.  I have a multilselect rendering in the editor template but that attribute doesn't get bound properly so that my action method sees it... that property is always null.

    Please advis,

    Chris
  6. Answer
    chris
    chris avatar
    19 posts
    Member since:
    Jan 2013

    Posted 26 Dec 2013 Link to this post

    Ok so it seems that I needed to format the list data using a javascript function before posting it to the server.

    <script type="text/javascript">
        var getUpdateData = function (data) {
            MultiSelectHelpers.serialize(data);
        };
     
        var MultiSelectHelpers = {
            serialize: function(data) {
                for (var property in data) {
                    if ($.isArray(data[property])) {
                        this.serializeArray(property, data[property], data);
                    }
                }
            },
            serializeArray: function(prefix, array, result) {
                for (var i = 0; i < array.length; i++) {
                    if ($.isPlainObject(array[i])) {
                        for (var property in array[i]) {
                            result[prefix + "[" + i + "]." + property] = array[i][property];
                        }
                    } else {
                        result[prefix + "[" + i + "]"] = array[i];
                    }
                }
            }
        };
    </script>
    change my helper definition like this:
    .Timezone("Etc/UTC")   
          .DataSource(
              d =>
                  {
                      d.Model(m=>
                      {
                          m.Id(i=>i.Id);
                      });
                      d.Read(r => r.Action("ReadEvents", "Outage", new { Area = "GatewayManagement" }).Type(HttpVerbs.Post));
                      d.Update(u => u.Action("UpdateEvent", "Outage", new { Area = "GatewayManagement" }).Data("getUpdateData").Type(HttpVerbs.Post));
                      d.Destroy(u => u.Action("DestroyEvent", "Outage", new { Area = "GatewayManagement" }).Data("getUpdateData").Type(HttpVerbs.Post));
                      d.Create(u => u.Action("CreateEvent", "Outage", new { Area = "GatewayManagement" }).Data("getUpdateData").Type(HttpVerbs.Post));
                  }
    Then the server binds the List<string> properly.  Not really sure why this is needed.  But came across this:


    http://stackoverflow.com/questions/16142746/kendo-ui-multiselect-post-binded-values-to-the-controller
  7. ShareDocs
    ShareDocs avatar
    76 posts
    Member since:
    Oct 2012

    Posted 16 Jan 2014 Link to this post

    chris, can you upload a working example?
    I'm trying to create a working multiselect inside a scheduler template but can't seem to grip the right way of doing this.

    Will appreciate any help with this as I am pretty stuck with trying to pass the data from the scheduler to the template...

    I followed your first post but I always get an empty model with the message:

     System.ArgumentNullException: Value cannot be null.
    Parameter name: source


    can you please assist?

    Telerik Team: forgive me for duplicating my question but this post seems to be very related to my problem
  8. ShareDocs
    ShareDocs avatar
    76 posts
    Member since:
    Oct 2012

    Posted 18 Jan 2014 Link to this post

    Eventually I did as telerik instructed on code library.
    Worked like a charm
Back to Top
UI for ASP.NET MVC is VS 2017 Ready