This question already has answers here:
Posting JSON Data to ASP.NET MVC

(9个答案)


4年前关闭。




如何在MVC 3操作中接收JSON作为模型(包含字典)?

浏览器端:将JSON发布到MVC3操作:
UpdateData :
{
   Id: 88991,
   Changes:
   {
      X:5,
      Y:6
   }
}

服务器端:
public class UpdateDataModel
{
    public int Id {get;set;}
    public IDictionary<string, string> Changes {get;set;}
}

public ActionResult SaveUpdateData(UpdateDataModel updateData)
{
    // updateData.Id should be 88991
    // updateData.Changes should be a dictionary containing X:5, Y:6
}

最佳答案

我认为应该是这样的:

UpdateData :
{
   Id: 88991,
   Changes:
   [
      { Key: 'X', Value: 5 },
      { Key: 'Y', Value: 6 }
   ]
}

10-06 00:04