Using ActionName in Web API

0

I am working with visual basic and AJAX, I want to access the following address in my controller called Catalogos:

    <HttpGet>
    <ActionName("BuscarProgramacion")>
    Public Function BuscarProgramacion(ByVal IdCuestionario As Integer) As List(Of ListaCatalogo)
        Dim Lista = sCatalogosEncuesta.ObtenerCatalogo(IdCuestionario)
        Return Lista
    End Function

I have already configured the WebApiConfig as follows:

    config.Routes.MapHttpRoute(
       name:="DefaultApi",
       routeTemplate:="api/{controller}/{id}",
       defaults:=New With {.id = RouteParameter.Optional}
    )

    config.Routes.MapHttpRoute(
       name:="ActionApi",
       routeTemplate:="api/{controller}/{action}/{IdCuestionario}",
       defaults:=New With {.id = RouteParameter.Optional}
   )

and my AJAX function is as follows:

    var url = 'http://localhost:7910/api/Catalogos/BuscarProgramacion/5';

    $.ajax({
        url: url,
        headers: { "Authorization": "Bearer " + OnLoadRA.token },
        type: 'GET',
        cache: false,
        statusCode: {
            200: function (data) {
                alert(data);
            },
            404: function (error) {
                jAlertError('Error al cargar la información.', 'Mensaje del servidor')
            }
        }
    });

but I can not access the driver, I get the following error:

{"Message": "No HTTP resource found matching the URI of the request ' link '. "," MessageDetail ":" No action was found on the' Catalogs' controller that matches the name 'SearchProgramming'. "}

    
asked by José MN 12.04.2017 в 20:54
source

1 answer

1

I understand that this action is within ApiController name CatalogosController

Getting Started with ASP.NET Web API 2 (C #)

Routing in ASP.NET Web API

I would recommend you evaluate the routing attribute [Route] is more practical to define how the action url resolves

Create a REST API with Attribute Routing in ASP.NET Web API 2

Also I do not see that you define a success in $.ajax to work the data that returns

If you define the url by means of PostMan you can try the invocation of the webapi without having to execute the code

    
answered by 17.04.2017 / 12:40
source