Nate
Nate

Reputation: 2084

OData v3 OdataActionParameter parameter Null Value Returned

Any Idea why my parameter is being returned as a null? Here is my controller.

[HttpPost]
[EnableQuery]
public IHttpActionResult LoadReports(ODataActionParameters parameters)
{

    if (!ModelState.IsValid)
    {
        throw new HttpResponseException(HttpStatusCode.BadRequest);
    }

    int key = (int)parameters["id"];  
    int year = (int)parameters["year"];

    return Ok(_reportsRepository.GetReports(key, year).Single());

}

---My EntitySet

 builder.EntitySet<Report>("Reports");

--MyEntity binding

var action = builder.Entity<Report>().Collection.Action("LoadReports");
        action.Parameter<int>("id");
        action.Parameter<int>("year");
        action.ReturnsFromEntitySet<Report>("Reports");

--My URL Call

http://localhost:6064/odata/Reports/LoadReports?id=5&year=2011

--My Error Message

   ReportsController.LoadReports(ODataActionParameters parameters) in \Controllers\ReportsController.cs:line 56
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

Upvotes: 0

Views: 2093

Answers (1)

Feng Zhao
Feng Zhao

Reputation: 2995

Unfortunately only v4 supports function which can be performed with GET.

With v3, if you want to define an action in the model and send GET request, you need to write your only routing convention to route the request to the right method in the right controller.

The default action routing convention only accepts POST.

And in the method, you can get the parameters from query part of the Request rather than ODataActionParameters.

Upvotes: 1

Related Questions