将Json Array传递给MVC Controller Action返回Null

时间:2015-07-24 15:29:06

标签: json asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 getjson

将Json Array传递给MVC Controller Action返回Null。

**controler*** 
public class TestData
{
    public string name1  { get; set; }
    public string value1 { get; set; }   
}

public JsonResult MyMethod(List<TestData> testVal)
    {
 //testval object having name1 and value1 null values
  }

查看页面

      $.getJSON("/viewFolderName/MyMethod",
         {
             testVal: [{ name1: "veea", value1: "0" }]

         },
         function (data) {
         //result
         });

将Json Array传递给MVC Controller Action返回Null

1 个答案:

答案 0 :(得分:0)

不,不要尝试在GET请求中发送JSON。将JSON与其他具有正文的动词一起使用,例如POST和PUT。

$.ajax({
    url: '/viewFolderName/MyMethod',
    type: 'GET',
    data: { testVal: [{ name1: "veea", value1: "0" }] },
    traditional: true,
    success: function (result) {
        console.log(JSON.stringify(result));
    }
});
相关问题