【问题标题】:Passing an integer id to post action in controller from angular 4从角度 4 传递整数 id 以在控制器中发布操作
【发布时间】:2018-06-23 21:08:53
【问题描述】:

我正在使用 REST 服务开发 Angular 4 应用程序。目前,我在使用参数id(Integer) 调用控制器时遇到了一个大问题。我的控制器包含以下操作:

 Get(), Get(int id), Post([FromBody] Model), Delete(int id)

这里,我还需要实现一个功能,那就是:

_this.http.post(_this.appService.baseUrl + "api/ServiceEmp/'", id).subscribe(result => {});

但代码不起作用,控制器中的操作收到 ZERO 而不是 id 值。

有什么解决办法,请帮帮我?

【问题讨论】:

    标签: angular rest model-view-controller controller http-post


    【解决方案1】:

    因为你写的时候

    _this.http.post(_this.appService.baseUrl + "api/ServiceEmp/'", id).subscribe(result => {});
    

    您返回的是订阅,而不是 Observable。

    试试这个

    _this.http.post(_this.appService.baseUrl + "api/ServiceEmp/'", id);
    

    并在您的控制器中订阅。

    【讨论】:

    • [HttpPost] [Route("{Id}")] public IActionResult Activate(int id) .Action 无效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    相关资源
    最近更新 更多