javascript - 我正在尝试将 JSON 对象发布到 ASP.NET MVC Controller ,但得到的是空 JSON

标签 javascript asp.net json post model-view-controller

这是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/

相关文章:

javascript - React - 从 Firebase 检索和打印数据

javascript - 无法更改数据表中的页面

javascript - 将 `refetch` 传递给上下文

c# 将行添加到datagridview删除其他行的内容

c# - 将复杂数组从 Controller 传递到 View ASP.NET MVC

javascript - 将 href 缓和到网站的 div/部分

c# - JavaScript 函数参数中的 '\' 是什么意思?

php - php 搜索 instagram 图片时出现 parseError

json - 我可以使用什么程序来创建和编辑 json 文件?

python - Stringify JSON -> Python Server 获取带有字符串化字符串键的字典