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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -