Kendo Mobile MVVM + Datasource simple POST call

2 posts, 0 answers
  1. Reggie Pangilinan
    Reggie Pangilinan avatar
    4 posts
    Member since:
    Oct 2009

    Posted 27 Sep 2013 Link to this post

    I have a kendo mobile app with a view  that is binded to an observable object 

    //Post Account View Model
            var postaccountModel = kendo.observable({
                Username: null,
                Password1: null,
                Password2: null,
                Firstname: null,
                Middlename: null,
                Lastname: null,
                Gender: null,
                BirthDate: null

    What i want basically is to just make a simple POST call using kendo datasource passing this viewmodel to webapi post method
    public class PostAccountModel
            public string Username { get; set; }
            public string Password1 { get; set; }
            public string Password2 { get; set; }
            public string Firstname { get; set; }
            public string Middlename { get; set; }
            public string Lastname { get; set; }
            public string Gender { get; set; }
            public DateTime? BirthDate { get; set; }
            [Authorize(Roles = Service.Security.Role.Guest)]
            public void Post(PostAccountModel value)

    But I cant figure out how, I tried this code but it doesnt work

    $("#button-save").on("click", function () {
                if (createaccountvalidator.validate()) {
                    var authheader = EMRGUEST;
                    var authbase64 = Base64.encode(authheader);
                    var dataSource = new{
                        transport: {
                            create: {
                                url: EMRAPIURL + "account",
                                dataType: "jsonp",
                                type: "POST",
                                beforeSend: function (xhr) {
                                    xhr.setRequestHeader('Authorization', 'Basic ' + authbase64);
                                data: kendo.stringify(postaccountModel)

    can anyone point me to the right direction on how to make this kind of call?

  2. Alexander Valchev
    Alexander Valchev avatar
    2887 posts

    Posted 01 Oct 2013 Link to this post

    Hi Reggie,

    For this particular scenario I suggest sending the model to the server via standard jQuery Ajax request.
    The DataSource is designed to operate with arrays of data, not a single observable object which is why it is not suitable.

    You may use the toJSON method to transport the observable into standard JavaScript object and serialize it in a way suitable for the service.

    I hope this will help. For more information please check jQuery.ajax API reference:

    Alexander Valchev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top