0
votes

Using angular i am trying to make a call to a web api controller with url

$http({ method: 'GET', url: '/ninja/clans/' })

My routing has config.MapHttpAttributeRoutes(); in the WebApiConfigs Register method.

The controller class that should receive the request from angular has the attribute [RoutePrefix("ninja")] on the whole clas and the method that should respond to the 'clans' part of the request has the attribute [Route("clans")] and the method is called Clans().

Controller.cs

    [Route("clans")]
    public Object Clans()
    {
        var returnList =  (from c in NinjaApi.GetAllClans()
                select new
                {
                    name = c.ClanName,
                    id = c.Id
                }).ToList();

        return returnList;
    }

I get this error when tryint to make the request:

{"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.String Get(Int32)' in 'NinjaWeb.Controllers.NinjaController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."}

How can i route the request to the method called clans?

1
Could you please add your controller code to the question? - Federico Dipuma
Done! Thanks for your time. - Daarwin

1 Answers

0
votes

I needed to add the attribute [HttpGet] to the method receiving the call.