如何使用mvvm剑道网格和post api控制器不调用发布数据

本文关键字:调用 布数据 数据 控制器 api mvvm 何使用 网格 post | 更新日期: 2023-09-27 17:50:46

我想发送数据从剑道网格到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,但网格读取所有值并显示在其中

如何使用mvvm剑道网格和post api控制器不调用发布数据

因为您要发布数据type: "POST"在创建方法中缺失。

并且检查data.models而不是data