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

Kendo DataSource create method not getting called

1 Answer 352 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 23 Jul 2015, 08:22 PM

I have a model that contains information about an event

    public class EventModel
    {
        public int ​EventId { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime RevenueStartDate { get; set; }
    }​

My view also contains a kendo grid to display a list of facilities associated with the event. One or more facilities can be associated with this model. However, there is no property to contain the list of associated facilities. I plan to handle that in the DataSource's transport methods. The Grid will contain just a list of facility names and will allow users to add additional facilities to the list (via the DataSource's create transport. Below is what I have so far but the create transport never gets called.

       var ds = new kendo.data.DataSource({
            transport: {
                read: {
                    cached: false,
                    url: '@Url.Action("ReadAllFacilities", "Tactic")',
                    dataType: "json"
                }
            }
        });

        var OrgdataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: '@Url.Action("ReadFacilities", "Tactic")',
                    dataType: "json"
                },
                create: {
                    url: '@Url.Action("Facility", "Tactic")',
                    type: "POST",
                    dataType: "json"
                }
            },
            batch: false
            schema: {
                model: {
                    id: "​Value",
                    fields: {
                        id: { type: "string", editable: false },
                        ​Text: { type: "string" }
                    }
                }
            }
        });

        $("#FacilityGrid").kendoGrid({
            dataSource: OrgdataSource,
            autoBind: true,
            autoSync: true,
            editable: { mode: "inline" },
            selectable: true,
            toolbar: ["save", "create"],
            columns: [
                { command: ["destroy"], title: " ", width: "150px" },
                { field: "Text", title: "Facility Name", editor: OrgDropDownEditor },
            ]
        });


        function OrgDropDownEditor (container, options) {
            $('<input required data-text-field="Text" data-value-field="Value" data-bind="value:' + options.field + '"/>')
                .appendTo(container)
                .kendoDropDownList({
                    autoBind: true,
                    dataSource: ds
                });
        }

 

 

And my controller Code:   
        [HttpPost]
        public JsonResult AddFacility(SelectListItem newFacility)
        {
            ...//THIS CODE NEVER GETS CALLED
        }

 

        [HttpGet]
        public string ReadAssociatedFacilities(int id)
        {
            var lst = new List<SelectListItem>();

            lst = dataProvider.GetAssociatedFacilities();

            var json = new JavaScriptSerializer().Serialize(lst);

            return json;

        }​


        [HttpGet]
        public string ReadAllFacilities()
        {
            var lst = new List<SelectListItem>();
            lst.Add(new SelectListItem() { Value = "​0", Text = "Facility 1" });
            lst.Add(new SelectListItem() { Value = "1", Text = "Facility 2" });
            var json = new JavaScriptSerializer().Serialize(lst);
            return json;
        }

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 27 Jul 2015, 01:45 PM

Hello Scott,

We have already provide an answer to your question in the support ticket you have opened on this matter. For completeness here is the excerpt for the reply:

Looking at the code you have pasted I have notices few issues:
 - The URL set for the create action does not match the action method you have pointed in the Controller - one is named Facility the other one is name AddFacility. I guess this may be the cause for the issue you have described.
 - The schema fields declaration is not correct as there is no field named id. I guess you meant Value.
 - The save toolbar command is designed to work with incell edit mode. The inline edit mode should be used with edit command placed inside the command column i.e.

   { command: ["destroy", "edit"], title: "&nbsp;", width: "150px" }
 - The autoSync option is DataSource setting not Grid option. However, it should be also used with incell edit mode only.

I hope this helps.

Regards,

Rosen

Telerik

 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
Scott
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or