asp.net mvc - Passing array of integers to webapi Method -


i trying pass array of int can not value in webapi method

var postdata = { "deletedids": deletedids };      $.ajax({         type: "delete",         traditional: true,         datatype: 'json',         contenttype: 'application/json',         cache: false,         url: "/api/management/models",         data: json.stringify(postdata),         success: modeldeleted,         error: modelnotdeleted     }); 

and in apicontroller :

[httpdelete]         public bool deletemodel(int[] deletedids)         {             return modelsrepository.deletemodels(deletedids);         } 

your code looking pretty ok me. please define structure of "deletedids" object. 1 suggestion use new array() object initialize deletedids property , remove json.stringify() . similar question asked here.

edit

web api supports parsing content data in variety of ways, not deal multiple posted content values. solution problem create viewmodel property of int[] type. code below,

public class simpleviewmodel {     public int[] deletedids{ get; set; } }  //controller [httpdelete]     public bool deletemodel(simpleviewmodel deletedids)     {         return modelsrepository.deletemodels(deletedids.deletedids);     } 

and use parameter type.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -