我无法从Post
向MVC controller
提出angular 2 (typescript) service
次请求。
export class LeaveService {
constructor(private _http: Http) { }
Add(model) {
let headers = new Headers({
'Content-Type':
'application/json; charset=utf-8'
});
let options = new RequestOptions({ headers: headers });
let body = JSON.stringify(model);
return this._http.post('/api/SampleData', body,
options).toPromise().catch(this.handleErrorPromise);
}
MVC控制器
[HttpPost]
public string Post([FromBody] Leave leave)
{
Response.StatusCode = 200;
try
{
// some logic
}
catch (Exception e)
{
Response.StatusCode = 400;
return e.ToString();
}
return "OK";
}
我在我的控制器上设置了断点但实际上没有击中。 错误在哪里?