ASP.NET Core 3.0 Web API-未找到控制器方法

问题描述 投票:1回答:2

我是ASP.NET Core Web API的新手-这是我的控制器方法:

[HttpPost]
[Route("Createnewlead")]
public IActionResult LeadCreate([FromBody]CRM_Lead Lead)
{
    // do stuff
}

这是我的json:

{
   "RegionID": "1",
   "RunningNo": "1633",
   "CardName": "Google Pte Limited",
   "Telephone": "65748394",
   "Mobile": "89349859",
   "Fax": "47850555",
   "Email": "[email protected]",
   "ROC": "28IO45h44",
   "OwnerEmail": "[email protected]"
}

enter image description here

请告诉我!

asp.net asp.net-core core asp.net-core-3.0
2个回答
1
投票

将您的路线更新为

[Route("api/[Controller]/Createnewlead")]

您的路线当前设置为[Route("Createnewlead")],它将转换为路线https://localhost:5001/createnewlead,但您正在呼叫https://localhost:5001/api/sap/createnewlead

或者,张贴至

 localhost:5001/Createnewlead

在您的示例中,您正在为每个操作设置路由,例如,也可以为每个Controller设置路由

[Route("api/[controller]/[action]")]
public class MyController: Controller 
{
}

[Route("[controller]/[action]")]
public class MyController: Controller 
{
}

[Route("[controller]")]
public class MyController: Controller 
{
}

这完全取决于您希望路由看起来像什么


0
投票

检查Ur路由属性和邮递员/浏览器URL,两者完全不同

您的路线属性没有路线“ api / sap / Createnewlead”,它只有“ Createnewlead”。

用您想要的网址更改您的路由属性网址

© www.soinside.com 2019 - 2024. All rights reserved.