2

Here is my js/ajax code:

    $.ajax({
        type: 'POST',
        data: JSON.stringify(jsonObj),
        url: 'filter/GetAjaxTestResult',
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        success: function (data) {
        alert(data);
      }
    });

And I want to post json as string. here is what I tried in mvc/controller:

[HttpPost]
public JsonResult GetAjaxTestResult(dynamic jsonString)
{
    return "";// Here jsonString is null!!!
}

How Can I get json as string? Is it possible?

4

1 に答える 1

7

このように渡します:-

  $.ajax({
            type: 'POST',
            data: "{'jsonString':'" + JSON.stringify(jsonObj) + "'}",
            contentType: "application/json; charset=utf-8",
            url: 'filter/GetAjaxTestResult',
            dataType: 'json',

            success: function (data) {

            alert(data);
          }
        });

もう 1 つのことは、アクションの戻り値の型が JsonResult であることです。残念ながら return ""; は実行できません。次のような JsonResult を返す必要がありますreturn Json(...)

于 2013-04-21T23:10:33.090 に答える