I want to make a web api that is passed 4 parameters.
Here is my route:
config.Routes.MapHttpRoute(
name: \"DefaultApi\",
public class Parameters
{
public int Param1 { get; set; }
public string Param2 { get; set; }
}
and then in your controller method:
[ActionName("DoSomething")]
[HttpPost]
public IHttpActionResult DoSomething(Parameters myParameters)
{
var x = myParameters.Param1;
var y = myParameters.Param1;
//do something else..
}
And build a ajax call like this:
var request = {
Param1 : "1",
Param2 : "Mystring"
};
function callToMethodController(request) {
var deferred = $q.defer();
$http.post('api/object/DoSomething', request)
.success(function (data) {
deferred.resolve(data);
}).error(function (error) {
deferred.reject('There was an error.');
});
return deferred.promise;
}