function GetViewModelData() {
var RDcViewModel = [];
var recordId = $.trim($("#recordId").val());
for (i = 1; i <= rowCount; i++) {
var item1 = $.trim($("#item1" + i).val()) == '' ? 0 : parseInt($("#item1" + i).val());
var item2 = $.trim($("#item2" + i).val()) == '' ? 0 : parseInt($("#item2" + i).val());
var GrandTotal = (item1 + item2);
var rdtCViewModel = new ItemDetailsViewModel(0, item1, item2, GrandTotal);
RDcViewModel.push(rdtCViewModel);
}
var obj = new ReportViewModel(recordId, RDcViewModel);
var viewmodel = JSON.stringify(obj);
return viewmodel;
}
我有上面的示例函數,我用來遍歷html錶行並將行值存儲在數組中。遍歷數組項和檢查屬性值
一旦我有我的數組填充,我使用下面的代碼段將數據發佈到我的控制器。
var PostData = function() {
$(".btnSubmit").click(function() {
var viewmodel = GetViewModelData();
//i want to check from here if viewmodel has any item(row) where GrandTotal is 0 (zero)
$.ajax({
async: true,
cache: false,
contentType: 'application/json; charset=utf-8',
data: viewmodel,
headers: GetRequestVerificationToken(),
type: 'POST',
url: '/' + virtualDirectory + '/Item/DataSave',
success: function (data) {
if (data == true) {
window.location.href = '/' + virtualDirectory + '/Destination/Index';
}
},
error: function (e) {
return false;
}
});
});
}
我現在想在我POSTDATA功能做的是檢查,如果我的「視圖模型」對象包含任何項目(行),其中「GrandTotal」 0
支票0,然後?? –
@Reddy並返回false – StackTrace
好的,你可以發佈你的'viewmodel'數據是什麼?我看到它的一個對象, –