Reputation: 33
I would like to pass multiple values to the following web api using angularjs typescript.
// POST api/values
public void Post([FromBody]string value1, [FromBody]string value2)
{
}
I would like to call the above method something like this
$http.post('api/values', ???)
As I need to do some validations on the page by passing multiple parameters to the database. I also tried with GET instead of post but didn't work for me.
Please share your thoughts.
Thank you. Hari C
Upvotes: 0
Views: 6006
Reputation: 37918
You can't read multiple values "FromBody". Instead you should define "Request" class with all needed parameters:
public class Request
{
public string Value1 { get; set; }
public string Value2 { get; set; }
}
//POST api/values
public void Post([FromBody]Request request)
{
}
And then like Aran said you can go this way
$http.post('api/values', {Value1:"foo", Value2:"bar"});
Upvotes: 1
Reputation: 1891
Use the data
property (the second argument of $http.post
) to pass your parameters:
$http.post('api/values', {x:"foo", y:"bar"});
Upvotes: 0