why do I have to match the parameter name to get json data from ajax call in MVC4 web app?

后端 未结 2 1302
眼角桃花
眼角桃花 2021-01-17 06:54

I just want to know why it\'s necessary for .NET to match parameter name with the JSON object\'s key name?

Quick code preview here...

var json = {
           


        
2条回答
  •  一个人的身影
    2021-01-17 07:39

    Base on post MVC controller : get JSON object from HTTP body? You action should be:

    [HttpPost]
    public ActionResult DATACRUD()
    {
        Stream req = Request.InputStream;
        req.Seek(0, System.IO.SeekOrigin.Begin);
        string json = new StreamReader(req).ReadToEnd();
        return Json(new { fromMVC = json });
    }
    

提交回复
热议问题