Web API code
[HttpGet]
public string GetMore([FromUri] Int32[] dd)
{
return "";
}
I need to be able to call this web api passing in an array of integers
The route at the WebApiconfig is as follows
config.EnableCors();
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
I try to access the method with the URL
- http://localhost/testApplication/api/questionnaire/GetMore/dd=1 Calls the method but the dd array list is empty that is no data is present in the dd array.
- http://localhost/testApplication/api/questionnaire/GetMore/?dd=1&dd=2&dd=3 i get an error
{"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'WebAPI.Services.Controllers.Questionnaire Get(Int32)' in 'WebAPI.Services.Controllers.QuestionnaireController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."}
None of them seem to work . I am sure im doing something wrong. Just not sure what that is ?