数据是通过AJAX传递给操作的对象数组

时间:2017-10-18 09:22:31

标签: c# mysql asp.net-core

这里我可以通过AJAX将数据作为对象数组传递给控制器​​,但是我在控制器端获得的值为null。

var newData  = [{Code:"FT",Id:1:Year:2005,TypeId:1,Value:20},
                {Code:"FR",Id:2:Year:2006,TYpeId:3,Value:40},
                {Code:"FY",Id:3:Year:2007,TYpeId:5,Value:50}]


$.ajax({
    url: "api/FG/cretejson",
    type: 'POST',
   contentType: "application/json",
   data: JSON.stringify({ extraParams: newData }),
   success: function (data) {
       var result = result;
   }
});

public JsonResult cretejson([FromBody]List<rev> extraParams)
{
    try
    {

        return Json(new { Result = "OK", Options = extraParams });
    }
    catch (Exception ex)
    {
        return Json(new { Result = "ERROR", Message = ex.Message });
    }
}
public class rev
{
    public string Id { get; set; }
    public string Code { get; set; }
    public int TypeId { get; set; }
    public int Year { get; set; }
    public int Value { get; set; }
}

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

AJAX电话:

concurrent.futures.ThreadPoolExecutor

Web API控制器:

 $.ajax({
       url: urlString,
       type: 'POST',
       data: sc,
       dataType: 'json',
       crossDomain: true,
       cache: false,
       success: function (data) { console.log(data); }
    });