我正在使用ASP.NET Core和AngularJS 2. http查询参数存在问题。无论我尝试什么,参数'quarter'
都不会传递给控制器。任何人都知道我在这里失踪了什么?
getBookingsBySaleUnit() {
let params: URLSearchParams = new URLSearchParams();
params.set('quarter', '1');
let requestOptions = new RequestOptions();
requestOptions.search = params;
this.http.get('/api/method', requestOptions).subscribe(result => {
this.sales = result.json();
}
);
}
答案 0 :(得分:1)
这对我有用:
let params: URLSearchParams = new URLSearchParams();
params.set('quarter', 1);
this.http.get('Result/Delete', { search: params })
.subscribe([...])
答案 1 :(得分:0)
您错过了传递参数。请尝试以下代码,其中包含网址中的参数。
getBookingsBySaleUnit() {
let params: URLSearchParams = new URLSearchParams();
params.append('quarter', '1');
let requestOptions = new RequestOptions();
requestOptions.headers.set('Content-Type', 'application/x-www-form-urlencoded');
this.http.get('/api/method?'+params.toString(), requestOptions).subscribe(result => {
this.sales = result.json();
});
}