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

Create on Datasource transport never fires WCF rest method

1 Answer 74 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Rod
Top achievements
Rank 1
Rod asked on 29 Jan 2013, 03:21 PM
I currently have an example that fires my delete, update, and read methods on my WCF rest service. For whatever reason, I cannot get the create to work. Am I doing something wrong?

<script>
        $(document).ready(function () {
            var crudServiceBaseUrl = "http://localhost/IqaRestService/Service1",
            dataSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: crudServiceBaseUrl + "/getquestions",
                        dataType: "json"
                    },
                    update: {
                        url: crudServiceBaseUrl + "/update",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json"
                    },
                    create: {
                        url: crudServiceBaseUrl + "/create",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json"
                    },
                    destroy: {
                        url: crudServiceBaseUrl + "/delete",
                        dataType: "json",
                        type: "DELETE",
                        contentType: "application/json"
                    },
                    parameterMap: function (options, operation) {
                        if (operation !== "read" && options) {
                            return kendo.stringify({ question: options });
                        }
                    }
                },
                schema: {
                    model: {
                        id: "QuestionId",
                        fields: {
                            QuestionId: { type: "string" },
                            QuestionText: { type: "string" },                           
                            Comment: { type: "string" },
                            Answer: { type: "string" }
                        }
                    }
                }
            });
 
            $(".k-add-button").click(function (e) {
                listView.add();
                e.preventDefault();
            });
 
            var listView = $("#listView").kendoListView({
                dataSource: dataSource,
                editable: true,
                selectable: "single",
                template: kendo.template($("#template").html()),               
                editTemplate: kendo.template($("#editTemplate").html())
            }).data("kendoListView");
 
        });
    </script>
[OperationContract]
        [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/getquestions")]
        public List<IqaQuestion> GetQuestions()
        {
            return this.Store;           
        }
 
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/update", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public bool SaveQuestion(IqaQuestion question)
        {           
            return true;
        }
 
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/create", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public bool CreateQuestion(IqaQuestion question)
        {           
            return true;
        }
 
        [OperationContract]
        [WebInvoke(Method = "DELETE", UriTemplate = "/delete", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public bool RemoveQuestion(IqaQuestion question)
        {
            return false;
        }

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 31 Jan 2013, 10:06 AM
Hello Rod,

Thank you for getting in touch with us.

I am not sure exactly where the problem comes from. Your Kendo configuration looks OK, so I assume that the problem might be connected with IDs of the records. A record will be synchronized through the create transport only if its ID value is empty. You can verify whether a given dataSource model is new with the isNew method.

Are you setting the QuestionId field on the client? Is the newly created record submitted via update request?

You may also find this forum thread useful as it discusses editing and IDs.

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ListView
Asked by
Rod
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or