0

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)
2
  • I think ODataActionParameters only come from request body? Commented Jul 14, 2014 at 9:42
  • passing multiple parameters require an ODataParameter and this must be done using a POST back, how can this ever be useful to someone who wants to query a table via REST? I need to perform a GET in JayData because that is all it allows but multiple parameters require a POST back. So, in reality, OData does not support multiple parameters as part of a URL call. Am I missing something? Only postbacks submit information to the body of the request and I simply need to consume a URL using multiple parameters in order to get results. I would think that this need would be expected by the designers. Commented Jul 14, 2014 at 18:59

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.