1

我想将数据从剑道网格发送到 sql 数据库,这是我的 javascript 视图模型代码:

  document.onreadystatechange = function () {
var viewModel = kendo.observable({

    products: new kendo.data.DataSource({

    schema: {
       //data:"Data",
        total: "Count",

        model: {
            Id: "Id",
            fields: {
                Id: { editable: true, type: "int" },
                ShortName: { editable:true, type: "string" },
                FullName: { editable: true, type: "string" },
                ContactPerson: { editable: true, type: "string" },
                CurrentCurrencyCode: { editable: true, type: "int" },
                Adress1: { editable: true, type: "string" },
                CompanyState: { editable: true, type: "string" },

                CompanyCity: { editable: true, type: "string" },
                CompanyCountry: { editable: true, type: "string" },
                ZipPostCode: { editable: true, type: "string" },
                TelArea: { editable: true, type: "string" }

            }
        }
    },
    batch: true,

    transport: {
        read: {
            url: "/api/Companies/GetAllCompanies",
            dataType: "json"
        },
        create:{

            url: "/api/Companies/SaveDefCompny", // here is a correct api url, which i want to call
            dataType: "json"
        },

        destroy: {
            url: "/api/Companies/Delete", 
            dataType: "json"
        },
        parameterMap: function (data, operation) {
            if (operation !== "read" && data) {
                return  kendo.stringify(data) ;
            }
        }
    }

})
});
kendo.bind(document.getElementById("example"), viewModel);


}

这是我将数据发布到数据库的控制器代码,但它没有通过单击创建或更新按钮来调用我的网格或控制器调用有什么问题?

    [HttpPost]
    public void SaveDefCompny(IEnumerable<DefCompanyDTO> DfCmpny1)
    {

        var result = new List<DefCompany>();
        using (var data = new RPDBEntities())
        {
            foreach (var productViewModel in DfCmpny1)
              {
                var product = new DefCompany
                {
                  Id = productViewModel.Id,
                    CurrentCurrencyCode = productViewModel.CurrentCurrencyCode,
                    ShortName= productViewModel.ShortName,
                    FullName= productViewModel.FullName,
                    ContactPerson= productViewModel.ContactPerson,
                    Address1= productViewModel.Address1,
                    CompanyCity= productViewModel.CompanyCity,
                    CompanyState= productViewModel.CompanyState,
                   CompanyCountry= productViewModel.CompanyCountry,
                   ZipPostCode= productViewModel.ZipPostCode,
                   TelArea= productViewModel.TelArea

                };
               result.Add(product);
               data.DefCompanies.Add(product);
          };
             data.SaveChanges();
        }

    }

url 是正确的,但即使在调试光标未转到 url 但网格读取所有值并显示在其中时,它也不会调用

4

1 回答 1

1

由于您要发布数据type: "POST",因此 create 方法中缺少数据。

并且还检查发布data.models而不是data

于 2015-10-10T07:00:15.797 回答