将JSON数组传递给MVC Controller Action无法正常工作

时间:2014-12-24 09:51:48

标签: arrays json asp.net-mvc-4

我们希望将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,而在视图(客户端)中,数组具有数据。有没有转换或丢失的东西?

0 个答案:

没有答案