【问题标题】:passing Json Array to MVC Controller Action returning Null将 Json 数组传递给 MVC 控制器动作返回 Null
【发布时间】:2015-07-24 15:29:06
【问题描述】:

将 Json 数组传递给返回 Null 的 MVC 控制器动作。

**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 数组传递给返回 Null 的 MVC 控制器动作

【问题讨论】:

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


【解决方案1】:

不,不要尝试在 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));
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    相关资源
    最近更新 更多