Passing array of integers to webapi Method

前端 未结 3 995
攒了一身酷
攒了一身酷 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 17:53

    Your code looking pretty Ok to me. Please define structure of "deletedIds" object. one suggestion is to Use new Array() object to initialize deletedIds property and remove JSON.stringify() . A similar question asked here.

    EDIT

    Web API supports parsing content data in a variety of ways, but it does not deal with multiple posted content values. A solution for your problem could be to create a ViewModel with a property of int[] type. Like code below,

    public class SimpleViewModel
    {
        public int[] deletedIds{ get; set; }
    }
    
    //Controller
    [HttpDelete]
        public bool DeleteModel(SimpleViewModel deletedIds)
        {
            return modelsRepository.DeleteModels(deletedIds.deletedIds);
        }
    

    and use it as parameter type.

提交回复
热议问题