0

剑道网格的另一个令人沮丧的一天。无论如何,我的问题是:当我在网格行项目上单击“编辑”时,它会进入编辑模式。好的。然后我修改一条记录,然后点击更新。我希望调用“/Company/SaveAccountAdmin”方法。但是没有......再次调用读取方法。当我单击“取消”时,记录就消失了!$("#save") 点击事件只是试图强制保存,但这些事件肯定可以从网格命令按钮触发吗?有什么想法吗?

/// <reference path="../kendo.all-vsdoc.js" />

$(document).ready(function () {

var CompanyId = $("#CompanyId").val();

var dataSource = new kendo.data.DataSource(
  {
      batch: true,
      pageSize: 10,

      transport: {
          create: {
              url: "/Company/SaveAccountAdmin",
              contentType: "application/json; charset=utf-8",
              type: "POST",
              dataType: "json",
              url: "/Company/ReadAccountAdmin",
          },

          read: {
              url: "/Company/ReadAccountAdmin"
          },

          update: {
              url: "/Company/SaveAccountAdmin",
              contentType: "application/json; charset=utf-8",
              type: "POST",
              dataType: "json",
              url: "/Company/ReadAccountAdmin",
          },
          //destroy: {},
          parameterMap: function (options, operation) {
              if (operation !== "read" && options.model) {
                  return { model: kendo.stringify(options.model) };
              }
          }
      },

      schema: {

          model: {
              id: "ComanyContactId",
              fields: {
                  CompanyId: { type: "number", editable: false, nullable: false, defaultVaue: CompanyId },
                  CompanyContactId: { type: "number", editable: false, defaultValue: 0 },
                  FirstName: { type: "string", nullable: false, validation: { required: true } },
                  LastName: { type: "string", nullable: false, validation: { required: true } },
                  Email: { type: "string", nullable: false, validation: { required: true } },
                  Phone: { type: "string", nullable: false, validation: { required: true } },
                  IsActive: { type: "boolean" }
              }
          }
      }
  });

$("#save").click(function (event) {

    event.preventDefault();

    var rows = $.map(dataSource.data(), function (value, index) {

        return {
            CompanyId: value["CompanyId"],
            CompanyContactId: value["CompanyContactId"],
            FirstName: value["FirstName"],
            LastName: value["LastName"],
            Email: value["Email"],
            Phone: value["Phone"],
            IsActive: value["IsActive"]
        }
    });


    var jsonCompanyContacts = JSON.stringify(rows);

    $.ajax({
        url: '/Company/SaveAccountAdmin',
        type: 'POST',
        traditional: true,
        data: { "jsonCompanyContacts": jsonCompanyContacts },
        success: alert("Data Saved")
    })
});


$("#AccountAdmins").kendoGrid({
    dataSource: dataSource,
    toolbar: ["create"],

    editable: "inline",
    sortable: true,
    pageable: true,
    navigatable: true,
    editable: "inline",
    columns: [
        { field: "CompanyId", title: "CompanyID", sortable: true },
        { field: "CompanyContactId", title: "Company ContactID", sortable: true },
        { field: "FirstName", title: "First Name", sortable: true },
        { field: "LastName", title: "Last Name" },
        { field: "Email", title: "Email", },
        { field: "Phone", title: "Phone", },
        { field: "IsActive", title: "Is Active" },
        { command: ["edit", "destroy"], title: "&nbsp;", width: "210px" }]

});

});

4

1 回答 1

0

我的猜测是,这是因为您为 Update 命令设置了读取 URL:

      update: {
          url: "/Company/SaveAccountAdmin", // <-- Not used because it is changed below
          contentType: "application/json; charset=utf-8",
          type: "POST",
          dataType: "json",
          url: "/Company/ReadAccountAdmin", // <-- Read URL set
      },
于 2013-02-07T23:52:30.760 回答