次のように、JSON オブジェクトを asp.net mvc コントローラー アクションに投稿しています。コントローラー アクションは、json 変数を個々のオブジェクトに自動的にバインドします。これは優れた機能ですが、私の要件は、着信 json 文字列を「そのまま」単一の文字列オブジェクトにキャプチャし、データベースに保存することです。私の質問は、デフォルトの動作をオーバーライドして、着信 json オブジェクトを単一の文字列で取得するにはどうすればよいですか?
見る
$.ajax({
type: "POST",
url: "@(storeLocation)IDR/OpcInsertCustomerProfile/",
data: JSON.stringify(currSelection),
contentType: "application/json",
success: function(data) {
alert('success : ' + JSON.stringify(data));
},
error: function(data) {
alert('Error : ' + JSON.stringify(data));
}
}
);
コントローラ
[HttpPost]
[ActionName("OpcInsertCustomerProfile")]
public JsonResult OpcInsertCustomerProfile(string jsonProfile)
{
try
{
JavaScriptSerializer ser = new JavaScriptSerializer();
return Json(jsonProfile, JsonRequestBehavior.AllowGet);
}
catch (Exception exc)
{
return Json(new { error = 1, message = exc.Message });
}
}