This is a migrated thread and some comments may be shown as answers.

object was not passed to the web api

5 Answers 81 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
siva
Top achievements
Rank 1
siva asked on 20 Jun 2015, 07:20 AM

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,

5 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 24 Jun 2015, 07:18 AM
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!
 
0
siva
Top achievements
Rank 1
answered on 22 Jul 2015, 01:57 PM

this is not helped me.

please provide me  the solution.

0
Vladimir Iliev
Telerik team
answered on 23 Jul 2015, 06:50 AM
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!
 
0
siva
Top achievements
Rank 1
answered on 23 Jul 2015, 01:56 PM

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

0
Vladimir Iliev
Telerik team
answered on 27 Jul 2015, 12:17 PM
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!
 
Tags
Scheduler
Asked by
siva
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
siva
Top achievements
Rank 1
Share this question
or