我们希望将JSON array
传递给MVC Controller Action
。操作将卡列表作为参数。当我们调用Action时,参数为null。
这是客户端代码:
function PrintCards() {
var CardsArray = [];
CardsArray = GenerateArrayOfCards();
//CardsArray has the desired data
var errors = JsonResults('/Operator/PrintCards', 'Cards=' + CardsArray, 'Post');
if (errors != '') {
alert('Something went wrong!');
return false;
}
alert('Cards got Successfully assigned.');
}
在服务器端,我们有以下Action
Public Function PrintCards(Cards As List(Of Card)) As JsonResult
Try
PrintAllCards(Cards)
Return Json(String.Empty, "application/json", UTF8Encoding.UTF8)
Catch ex As Exception
Return Json(New With {.error = "Something went wrong!"}, "application/json", UTF8Encoding.UTF8)
End Try
End Function
问题在于,在Action中,Cards为null,而在视图(客户端)中,数组具有数据。有没有转换或丢失的东西?