Passing array of integers to webapi Method

前端 未结 3 996
攒了一身酷
攒了一身酷 2020-12-10 17:38

I am trying to pass an array of int but I can not get the value in the webapi method

var postData = { \"deletedIds\": deletedIds };

    $.ajax({
        typ         


        
3条回答
  •  忘掉有多难
    2020-12-10 18:12

    At last, based on @Shashank Answer it worked and the code modified as :

    var deletedIds = new Array();
    
    deletedIds.push(modelId);
    
    var postData = { "DeletedIds": deletedIds };
    $.ajax({
        type: "Delete",
        traditional: true,
        dataType: 'json',
        cache: false,
        url: "/api/Management/Models",
        data: postData,
        success: ModelDeleted,
        error: ModelNotDeleted
    });
    

    and the apiController :

    [HttpDelete]
            public bool DeleteModels(DeleteViewModel dvm)
            {
                return modelsRepository.DeleteModels(dvm.DeletedIds);
            }
    

    and for the DeleteViewModel :

    public class DeleteViewModel
        {
            public int[] DeletedIds { get; set; }
        }
    

提交回复
热议问题