1

I need to convert the request from get to post in two contexts: - in the case of the standard controller - in the case of web api in an asp.net core c # project.

Here are the method declarations. Standard controller:

public async Task<IActionResult> Details(string id)

Web Api Controller:

[HttpGet("{deviceIdorId}/{action2}")] 
public async Task<IEnumerable<CosmosDBTelemetry>> GetAsync(string deviceIdorId,string action2)   

What should I do?

Thanks,

Simone

Simone Spagna
  • 626
  • 7
  • 27

1 Answers1

1

for convert HttpGet method to post you can create a view model to pass data. for example:

Web Api

public class ApiDto
{
      public string deviceIdorId { get; set;}
      public string action2{ get; set;}
}

[HttpPost("ActionName")] 
public async Task<IEnumerable<CosmosDBTelemetry>> ActionName(ApiDto dto)  

Controller:

public class IdDto
{
      public string Id{ get; set;}
}
[HttpPost()]
public async Task<IActionResult> Details(IdDto id)
Farhad Zamani
  • 5,381
  • 2
  • 16
  • 41
  • Could you please tell me also what I have to do to call the method ? I mark your post as the answer. Could you vote my question, please? Thanks a lot Simone – Simone Spagna Jul 27 '19 at 11:34
  • Good luck ;). you must pass the parameters from the body to method. check this [link](https://stackoverflow.com/a/20226220/7086678) to send data to post actions in api – Farhad Zamani Jul 27 '19 at 11:40