动态表生成这样的标记
<div>
<table class="table table-striped table-hover table-bordered" id="OutstandingInvoicesTable">
<thead>
<tr>
<th>ID</th>
<th>Date</th>
<th>Description</th>
<th>Debit</th>
<th>Credit</th>
<th>Pay</th>
</tr>
</thead>
<tbody>
<tr>
<td>377</td>
<td>7/9/2013</td>
<td title='Payment on account from system'>Payment on</td>
<td class="pTransactionRight">$0.00</td>
<td class="pTransactionRight">$231.56</td>
<td>
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="checkbox_PaymentChecked_377"/>
<span class="custom-control-indicator"></span>
</label>
</td>
</tr>
</tbody>
</table>
</div>
POST一个数组的jquery
//Outstanding invoices check changed
$('body').on('change', '.custom-control-input', function () {
//Send to controller to work out total of selected rows and total
var vTable = new Array();
$('#OutstandingInvoicesTable tbody tr').each(function () {
var row = $(this);
var rows = {};
rows.ID = row.find("td").eq(0).html();
rows.Debit = row.find("td").eq(3).html();
rows.Credit = row.find("td").eq(4).html();
rows.Selected = row.find("input").eq(0).prop('checked');
//alert(rows.Selected);
vTable.push(rows);
});
jQuery.ajax({
url: '@Url.Action("SelectInvoicesValuesChanged", "Account")',
type: 'POST',
contentType: "application/json; charset=utf-8",
dataType: "json",
traditional: true,
data: JSON.stringify(vTable),
success: function (response) {
ModalSuccess(response);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
ModalError(textStatus + " - " + errorThrown);
}
})
})
似乎工作 - 警报将始终返回正确的值 - 但是当它到达控制器时
<HttpPost()>
Function SelectInvoicesValuesChanged(vList() As List(Of String)) As ActionResult
Try
Dim vRows As Integer = vList.Count
Return Json(vRows)
Catch ex As Exception
EmailError(ex, 846, PageName)
Return Json("Error")
End Try
End Function
它返回正确的行数,但每一行都没有!
有任何想法吗?
Public Class AccountModel
Public Class InvoiceTransactions
Public Property TransactionID() As String
Get
Return v_TransactionID
End Get
Set(value As String)
v_TransactionID = value
End Set
End Property
Private v_TransactionID As String
Public Property Debit() As String
Get
Return v_Debit
End Get
Set(value As String)
v_Debit = value
End Set
End Property
Private v_Debit As String
Public Property Credit() As String
Get
Return v_Credit
End Get
Set(value As String)
v_Credit = value
End Set
End Property
Private v_Credit As String
Public Property Selected() As Boolean
Get
Return v_Selected
End Get
Set(value As Boolean)
v_Selected = value
End Set
End Property
Private v_Selected As Boolean
End Class
Public Property Transaction() As List(Of InvoiceTransactions)
Get
Return v_InvoiceTransactions
End Get
Set(value As List(Of InvoiceTransactions))
v_InvoiceTransactions = value
End Set
End Property
Private v_InvoiceTransactions As List(Of InvoiceTransactions)
End Class
<HttpPost()>
Function SelectInvoicesValuesChanged(vList As List(Of AccountModel.InvoiceTransactions)) As ActionResult
Try
Dim vTotal As Decimal = 0
Dim vRows As Integer = vList.Count
If vRows > 0 Then
For Each Row In vList
If Row.Selected = True Then
Dim vID As Integer = Row.TransactionID
Dim vDebit As Decimal = Row.Debit
Dim vCredit As Decimal = Row.Credit
vTotal += vDebit - vCredit
End If
Next
End If
Return Json(vTotal)
Catch ex As Exception
EmailError(ex, 846, PageName)
Return Json("Error")
End Try
End Function