0

I have a CostCenter ComboBox trying to grab an ID of the selected item from CompanyCode comboBox and pass it into an URL, but I don't understand why I keep getting "undefined" in the URL.

---JS---

             $("#companyCode").width(500).kendoComboBox({
                placeholder: "Select...",
                dataTextField: "CompanyDescription",
                dataValueField: "Id",
                autobind: false,
                template: "#: data.CompanyCode# - #: data.CompanyDescription#",
                dataSource: {
                    serverFiltering: true,
                    transport: {
                        read: {
                            url: "./CompanyCodeCostCenter/GetAll",

                            // the request type
                            type: "get",

                            // the data type of the returned result
                            dataType: "json",

                        }
                    }
                },
                change: function () {
                    companyCodeId = this.value();
                }
            });

            $("#costCenter").width(500).kendoComboBox({
                placeholder: "Select...",
                dataTextField: "CostCenterDescription",
                dataValueField: "Id",
                template: "#: data.CostCenterNo# - #: data.CostCenterDescription#",
                autobind: false,
                cascadeFrom: "companyCode",
                dataSource: {
                    serverFiltering: true,
                    transport: {
                        read: {
                            url: "./CompanyCodeCostCenter/Get" + companyCodeId,

                            // the request type
                            type: "get",

                            // the data type of the returned result
                            dataType: "json",

                        },
                        parameterMap: function (data, type) {
                            if (type == "read" &&
                                data.filter != undefined &&
                                data.filter.filters != undefined ){
                                var filter = data.filter.filters;
                                return {
                                    id: filter[0].value,
                                }
                            }
                        }
                    }
                }
            });

---Controller---

public virtual JsonResult Get(int id)
        {
            SetUser();
            var vo = _viewService.Get(id);
            ExpirePage();
            return Json(vo, JsonRequestBehavior.AllowGet);
        }

---Result---

http://localhost/Tax/CompanyCodeCostCenter/Getundefined?id=21

I'm very new to JS & Kendo. If possible, please explains in detail. Thank you

dnguyen
  • 1
  • 2

1 Answers1

0

I think this article should help you achieve what you're looking for: https://docs.telerik.com/kendo-ui/controls/editors/combobox/cascading#what-to-do-when-i-cannot-get-the-request-parameters-on-the-server

$("#costCenter").width(500).kendoComboBox({
    placeholder: "Select...",
    dataTextField: "CostCenterDescription",
    dataValueField: "Id",
    template: "#: data.CostCenterNo# - #: data.CostCenterDescription#",
    autobind: false,
    cascadeFrom: "companyCode",
    dataSource: {
        serverFiltering: true,
        transport: {
            read: {
                url: "./CompanyCodeCostCenter/Get" + companyCodeId,

                // the request type
                type: "get",

                // the data type of the returned result
                dataType: "json",

                // use this instead of parameter map
                data: function () {
                    return { id: $('#companyCode').val() }
                }
            }
        }
    }
});

I added the data property to the transport.read object.

Pedro Estrada
  • 224
  • 1
  • 6