这是Javascript代码
$("#JSONPost").click(function (e) {
var jsonData = { name: "ramesh", mobile: "9xxxxxxxxx" };
$.post(
"/Trace/JSONPostMethod",
jsonData,
function (data, status) {
alert(status);
});
});
});
public ActionResult JSONPostMethod(object data)
{
}
数据以 {}
的形式出现,而不是 { name: "ramesh", mobile: "9xxxxxxxxx"}
知道如何获取此 JSON 吗?我不想创建模型类来获取数据。
最佳答案
找到解决方案。在 Controller 方法中执行此操作,
var resolveRequest = HttpContext.Request;
resolveRequest.InputStream.Seek(0, SeekOrigin.Begin);
string jsonString = new StreamReader(resolveRequest.InputStream).ReadToEnd();
关于javascript - 我正在尝试将 JSON 对象发布到 ASP.NET MVC Controller ,但得到的是空 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59408791/