該課程通過AJAX帖子進行填充。我該如何檢查一個可爲空的整數數組是否爲空?
public class FilterViewModel
{
public int?[] size { get; set; }
public decimal? Price { get; set; }
}
價格屬性可以很容易地通過
if (Price.HasValue)
{
}
但對於大小屬性來檢查? 雖然被聲明爲可爲空和內不存在任何數據,這裏是燒出來......
下面是數據發佈
而在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");
});
僅用於說明目的:'size'是一個可爲空的整數*的數組,您不「將數組聲明爲可空」 - 數組是參考類型。 – kaveman
@kaveman我完全同意,但是我的大腦燒了什麼,是從哪裏產生位置0的空值。 – OrElse
那麼,AJAX的帖子有問題嗎?數組如何生成服務器端? –