Why does the update operation not publish any data?

I am using a Kendo grid with built-in editing. When I click the Refresh button, POST gets my controller method with this signature. The controller action gets in, so POST works.

[HttpPost]
    public HttpResponseMessage SaveAccountAdmin(string jsonCompanyContacts)

However, the POST data in the update operation never appears - its always null.

update: {
              url: "/Company/SaveAccountAdmin",
              contentType: "application/json; charset=utf-8",
              type: "POST",
              dataType: "json",
              data: {
                  jsonCompanyContacts: "John Doe"
              }
          },

Here is the complete data source code.

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

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

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

          update: {
              url: "/Company/SaveAccountAdmin",
              contentType: "application/json; charset=utf-8",
              type: "POST",
              dataType: "json",
              data: {
                  jsonCompanyContacts: "John Doe"
              }
          },
          //destroy: {},

          parameterMap: function (data, type) {
              return kendo.stringify(data);
          }
      },

this doesn't work either:

update: {
              url: "/Company/SaveAccountAdmin",
              contentType: "application/json; charset=utf-8",
              type: "POST",
              dataType: "json",
              //data: { "jsonCompanyContacts": kendo.stringify({ jsonCompanyContacts: "John Doe" }) }

              data: { "jsonCompanyContacts": "John Doe" }
          },
          //destroy: {},

          parameterMap: function (data, type) {
              return kendo.stringify(data);
          }

BUT THIS WORK - WHY?

update: {
              url: "/Company/SaveAccountAdmin",
              contentType: "application/json; charset=utf-8",
              type: "POST",
              dataType: "json",
              //data: { "jsonCompanyContacts": kendo.stringify({ jsonCompanyContacts: "John Doe" }) }

              //data: { "jsonCompanyContacts": "John Doe" }
          },
          //destroy: {},

          parameterMap: function (data, type) {
              return kendo.stringify({ "jsonCompanyContacts": "John Doe" });
          }
+5
source share
3 answers

The value is not passed to the controller as a string. Try using a model. This may help: MVC3 and JSON.stringify () ModelBinding returns a null model

UPDATE

. , , .

Model

public class CompanyContactModel
{
    public string CompanyContacts { get; set; }
}

public JsonResult SaveAccountAdmin(CompanyContactModel companyContactModel)
...

public JsonResult SaveAccountAdmin([DataSourceRequest]DataSourceRequest request, CompanyContactModel companyContactModel)
    ...
    Update and Return and put into List
    If error: ModelState.AddModelError(string.Empty, e.Message);

    DataSourceResult result = [Your Model List].ToDataSourceResult(request, ModelState);
    return Json(result, JsonRequestBehavior.AllowGet);
}
+1

:

  update: {
      url: "/Company/SaveAccountAdmin",
      contentType: "application/json; charset=utf-8",
      type: "POST",
      dataType: "json",
      data:{ "jsonCompanyContacts":  kendo.stringify({ jsonCompanyContacts: "John Doe"  })}
      }

, . , , . .

, .

+1

, . broswer, .

"[ScriptIgnore (ApplyToOverrides = true)]" , .

0
source

All Articles