[英]How to pass multiple post parameters to web api using angular typescript
I would like to pass multiple values to the following web api using angularjs typescript. 我想使用angularjs打字稿将多个值传递给以下Web API。
// 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.
我也尝试使用GET而不是post,但是对我不起作用。
Please share your thoughts. 请分享您的想法。
Thank you. 谢谢。 Hari C
哈里·C
You can't read multiple values "FromBody". 您无法读取多个值“ FromBody”。 Instead you should define "Request" class with all needed parameters:
相反,您应该使用所有必需的参数定义“ Request”类:
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"});
使用data
属性( $http.post
的第二个参数)传递参数:
$http.post('api/values', {x:"foo", y:"bar"});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.