object was not passed to the web api

6 posts, 0 answers
  1. siva
    siva avatar
    3 posts
    Member since:
    Jun 2015

    Posted 20 Jun 2015 Link to this post

    Hi,

    I have written as following for creating the Schedule

      dataSource: {
                        batch: true,
                        transport: {
                            read: {
                                url: "http://localhost:2237/api/values/GetSchedule",
                                dataType: "jsonp"
                            },
                            update: {
                                url: "http://demos.telerik.com/kendo-ui/service/tasks/update",
                                dataType: "jsonp"
                            },
                            create: {
                                method:"post",
                                url: "http://localhost:2237/api/values/SaveSchedule",
                                data: ,
                                contentType: "application/json;charset=utf-8",
                                dataType: "json"
                            },
                            destroy: {
                                url: "http://demos.telerik.com/kendo-ui/service/tasks/destroy",
                                dataType: "jsonp"
                            },
                            parameterMap: function (options, operation) {
                                if (operation !== "read" && options.models) {
                                    return { models: kendo.stringify(options.models) };
                                }
                            }
                        },

    in the above in create section how can i pass the object to the api .

    In Api

      public void SaveSchedule(Schedular callback)
            {
               
            }

    here Schedular is a class consisting of all properties with same name in the ui.

    whenever i have saved the data , in the api it shown as callback null.

     

    Can you please provide me the solution for this.

     

    Thanks,

  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2206 posts

    Posted 24 Jun 2015 Link to this post

    Hello Siva,

    Please note that the request "callback" parameter type is a string (not an object). For more information on the matter you can check the following thread at StackOverflow:

    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. siva
    siva avatar
    3 posts
    Member since:
    Jun 2015

    Posted 22 Jul 2015 in reply to Vladimir Iliev Link to this post

    this is not helped me.

    please provide me  the solution.

  4. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2206 posts

    Posted 23 Jul 2015 Link to this post

    Hello Siva,

    Please check the example below which shows how to bind the callback on the client side:

    Client side:
    dataSource: {
        batch: true,
        transport: {
            create: {
                url: "/Home/Tasks_Create",
                dataType: "jsonp"
            },

    Controller:
    public JsonResult Create()
    {
        var tasks = this.DeserializeObject<IEnumerable<TaskViewModel>>("models");
     
        if (tasks != null)
        {
            foreach (var task in tasks)
            {
                TasksRepository.Insert(task);
            }
        }
     
        return this.Jsonp(tasks);
    }

    Example JSONP class implementation:
    public class JsonpResult : JsonResult
    {
        public JsonpResult(string callbackName)
        {
            CallbackName = callbackName;
        }
     
        public JsonpResult() : this("jsoncallback")
        {
        }
     
        public string CallbackName { get; set; }
     
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
     
            var request = context.HttpContext.Request;
            var response = context.HttpContext.Response;
     
            string jsoncallback = ((context.RouteData.Values[CallbackName] as string) ?? request[CallbackName]) ?? CallbackName;
     
            if (!string.IsNullOrEmpty(jsoncallback))
            {
                if (string.IsNullOrEmpty(base.ContentType))
                {
                    base.ContentType = "application/x-javascript";
                }
                response.Write(string.Format("{0}(", jsoncallback));
            }
     
            base.ExecuteResult(context);
     
            if (!string.IsNullOrEmpty(jsoncallback))
            {
                response.Write(")");
            }
        }
    }
     
    public static class ControllerExtensions
    {
        public static JsonpResult Jsonp(this Controller controller, object data, string callbackName = "callback")
        {
            return new JsonpResult(callbackName)
            {
                Data = data,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
     
        public static T DeserializeObject<T>(this Controller controller, string key) where T : class
        {
            var value = controller.HttpContext.Request.QueryString.Get(key);
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
            return javaScriptSerializer.Deserialize<T>(value);           
        }
    }

    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  5. siva
    siva avatar
    3 posts
    Member since:
    Jun 2015

    Posted 23 Jul 2015 in reply to Vladimir Iliev Link to this post

    Hi Vladimir ,

    the following method i can't replicate 

    public JsonResult Create()
    {
        var tasks = this.DeserializeObject<IEnumerable<TaskViewModel>>("models");

        if (tasks != null)
        {
            foreach (var task in tasks)
            {
                TasksRepository.Insert(task);
            }
        }

        return this.Jsonp(tasks);
    }​

    here getting errors on Jsonp,DeserializeObject and TaskViewModel

    can you please provide me the sample solution with VS2013 as rar.

     

    Thanks

  6. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2206 posts

    Posted 27 Jul 2015 Link to this post

    Hi,

    Currently we have no complete demo which we can provide - that could you please provide the (runable) sample project where the described issues can be reproduced? This I will get better overview of the exact setup that you have and advice you better how to proceed. 

    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top