0

I am having trouble calling a method with a string parameter in asp.net core web api. The method doesn't get called or invoked.

** My Class looks like this **

[Route("api/[controller]")]
[ApiController]
public class MyClass : ControllerBase
{
    [HttpGet("dispatch_discrepancies/{airwayBillNumber}")]
    public List<Discrepancy> GetDispatchDiscrepancies(string airwayBillNumber)
        {
                ....
        }
    }

Below is my route configuration.

app.UseMvc(routes => {
    routes.MapRoute(
    name: "default",
    template: "{controller=Home}/{action=Index}/{id?}");
});
Kaptin Koda
  • 51
  • 1
  • 5
  • Controllers annotated with `[ApiController]` will ignore the routing conventions that you set up with `UseMvc()` and will always require attribute routing. That being said, the route for that endpoint should be `/api/MyClass/dispatch_discrepancies/`. What URL are you trying to access it with? – poke Jul 27 '19 at 12:58
  • @poke It is still not working for me. I am fairly new at this and not having any luck online either. Can you state exactly how I should annotate my class and method as well? – Kaptin Koda Jul 27 '19 at 13:17
  • I have tried you code and it works well.Do you have the problem when test in a brand new web api project? – Ryan Jul 29 '19 at 08:51
  • Hello All, Sorry I replied to my question but it seems it didn't get through. My code is working just fine. I was making a silly mistake of calling the method as a post instead of get. Thanks so much. grateful – Kaptin Koda Jul 30 '19 at 14:17

0 Answers0