angularjs - Passing parameter from angular js for a POST web api method -


i have used sample code upload control.

web api call angularjs controller given below

var uploader = $scope.uploader = new fileuploader({     url: window.location.protocol + '//' + window.location.host + '/api/fileupload/uploadfile',     data:{seldoctype:"1"} }); 

the post web api method

    [system.web.http.httppost]     public ihttpactionresult uploadfile(string seldoctype)     {..} 

in browser, fileuploader obj had below info along others

 data: object ->seldoctype: "1" method: "post" url: "http://localhost:90/api/fileupload/uploadfile" 

the call works fine if remove seldoctype paramter( in api controller). when try add parameter, api call not happen. assuming not passing parameter in right way. can please help.

thanks

you need have object post method argument instead of string.

first create class seldoctype propery , keep class argument of post method.

class document { public string seldoctype {get;set;} } 

now use class in post method argument

[system.web.http.httppost] public ihttpactionresult uploadfile(document document) {..} 

post method takes object type parameter.


Comments