Post array of strings to web API method

前端 未结 7 1317
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 14:42

this is my client side ajax call:

    var list = [\"a\", \"b\", \"c\", \"d\"];

    var jsonText = { data: list };

    $.ajax({
        type: \         


        
7条回答
  •  一向
    一向 (楼主)
    2021-02-14 15:03

    You should pass the list itself, and not any other object wrapping it.

    E.g. pass the following:

    var list = ["a", "b", "c", "d"];
    

    in

    $.ajax({
            type: "POST",
            url: "/api/scheduledItemPriceStatus/updateStatusToDelete",
            // Pass the list itself
            data: list, 
            dataType: "json",
            traditional: true,
            success: function() { alert("it worked!"); },
            failure: function() { alert("not working..."); }
        });
    

    Your method signature on server is correct.

提交回复
热议问题