简体   繁体   English

从Angular调用时未获取所需的ASP.Net Web API方法

[英]Not getting the required ASP.Net web API method while calling from Angular

I am working on project in which I want to add a value to an Oracle database and get value from it. 我正在做一个项目,我想在其中添加一个值到Oracle数据库并从中获取价值。 I am using Angular 4 using VSCode and ASP.NET Web API using Visual Studio 2015 for services. 我正在使用VSCode的Angular 4和将Visual Studio 2015用于服务的ASP.NET Web API。

My Angular code is working well and Web API code also working while calling from browser but when I call same method from Angular its not htting. 从浏览器调用时,我的Angular代码运行良好,Web API代码也可以运行,但是当我从Angular调用相同的方法时却无法正常运行。 Its hit the constructor but it's not hitting the required method in the ASP.NET Web API while calling. 它会调用构造函数,但是不会在调用时调用ASP.NET Web API中的必需方法。 Kindly suggest what I have to do.... Help would be appriciated. 请建议我该怎么做。...将寻求帮助。 My API code is this: 我的API代码是这样的:

[HttpPost]
public IHttpActionResult SaveCustomer( UserInfo user )
{
    // int result;

    // result = _customerManager.SaveCustomer(user);
    // if (result > 0)
    // {
    //    return Ok(result);
    // }
    // else
    // {
    //    return NotFound();
    // }
    return null;
}

My service code is this: 我的服务代码是这样的:

register(userInfo: any) {
    debugger; 

    var url1 = this.baseUrl;
    url1 += "api/Account/Register";

    return this._http.post(url1, userInfo);


};

And path is 路径是

BASE_API_URL: "http://localhost:12795/",

Try decorate your API functions and your constructor, eg 尝试装饰您的API函数和构造函数,例如

[Route("api/[controller]/[action]")]
public class AccountController : Controller

public AccountController (...){

    ....
   [HttpPost, ActionName("Register")]
   public IHttpActionResult SaveCustomer([FromBody] UserInfo user ){}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM