我怎样才能检查一个可以为空的整数数组是否为Null?

时间:2015-09-26 22:18:44

标签: c# ajax nullable

此课程通过AJAX帖子填充。

   public class FilterViewModel
        {
            public int?[] size { get; set; }
            public decimal? Price { get; set; }
        }

可以通过

轻松查看价格属性
if (Price.HasValue)
{

}

但是尺寸属性怎么样? 虽然它被声明为可以为空并且内部没有数据,但这里有烧坏......

enter image description here

以下是发布的数据

enter image description here

在RAW中

{"man":"2","size":"","color":"","Order":"0","Sorting":"0"}

Ajax帖子以

执行
$.ajax({
                url: path, type: "POST", cache: "false",
                dataType: "json", contentType: "application/json; charset=utf-8",
                data: JSON.stringify(postData),
                traditional: true,
                converters: {'text json': true}
            }).success(function (responseText) {
                $('#Grid').replaceWith(responseText);
            }).error(function (responseText){
                swal("Error!", "Ooops", "error");
            });

1 个答案:

答案 0 :(得分:2)

数组是引用类型,不管其中存储了什么类型的值,因此要检查null - size.All(x => !x.HasValue)

但看起来你实际上在数组中有元素 - 你也可以检查所有元素是否为" null"用{{1}}。

之类的东西

请注意,上面回答了您的问题,但它不太可能有助于解决您的问题,这可能与请求发送到服务器的方式有关。正如使用Fiddler的评论所示,查看确切的请求可能有所帮助。

相关问题