Json发布的数组具有空值 [英] Json posted array has null values

查看:235
本文介绍了Json发布的数组具有空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下json对象,对不起图片;

I have the following json object, sorry for the image;

我拥有的jquery代码如下:

The jquery code I have looks like this;

var data = {
    table: table,
    favour: $("[name='radFavour']:checked").val(),
    data: jsonObj
};

$.ajax({
    url: appDomain + "/Compare/Ajax_Update",
    type: "post",
    dataType: "json",
    data: data
});

c#代码如下;

[HttpPost]
public void Ajax_Update(CompareFVM fvm)
{
}

FVM包含用于表和帮助的字符串,并且这两个属性的数据均通过.

The FVM contains a string for table and for favour and the data for those two properties comes through.

对于数据",我在FVM中具有以下内容;

For "data" I have the following in the FVM;

public List<CompareItem> data { get; set; }

还有物品;

public class CompareItem
{
    public int prodId { get; set; }
    public int stageId { get; set; }
    public string value { get; set; }
    public string property { get; set; }
}

列表中有正确数量的元素,在这种情况下为两个,但是每个元素都设置了空值.

The List has the correct amount of elements in it, in this case two, but each of them has nulls set.

所以我发回的数据不是数组元素的数据,而是单个字段的数据.

So the data I am posting back is not coming through for the array elements but it is for the single fields.

有什么想法吗?

推荐答案

在进行ajax调用时,将对象名称作为'fvm'传递(名称应与C#代码参数匹配).另外,请使用JSON.stringify(data)检查传递的json abject.

while ajax calling, pass the objectname as 'fvm'(name should be matching with the C# code parameter). also, please check passing json abject using JSON.stringify(data).

    var fvm = {
        table: table,
        favour: $("[name='radFavour']:checked").val(),
        data: jsonObj
    };

    $.ajax({
        url: appDomain + "/Compare/Ajax_Update",
        type: "post",
        dataType: "json",
        data: JSON.stringify(fvm)
    });

这篇关于Json发布的数组具有空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆