Ratha
Ratha

Reputation: 9692

why my ODataACtionParameters are null for POST request?

Im new to .net development. Im trying to post a request to an webservice.

Webservice implementaion

[HttpPost]
    public async Task<ICollection<BoConsolidatedData>> GetTesDatas(ODataActionParameters actionParameters)
    {
        try
        {
            var reqId = (int)actionParameters["ReqId"];

I use Chrome Advance REST client,where I set content type to application/json

I sent parameter in the body as JSOn

{"ReqId":9481}

When I debug the service my actionparameters are always null. What is wrong here?

Upvotes: 1

Views: 2390

Answers (2)

James L.
James L.

Reputation: 14515

This could also happen if you mess up your parameters a bit. For example, if you have a nullable Guid? parameter in WebApiConfig but the client passes in an "" empty string, this will cause the parameters to be null.

Upvotes: 1

GWigWam
GWigWam

Reputation: 2124

Have you registered this function? Code should probably look something like this:

var builder = new ODataConventionModelBuilder();

builder.Function("GetTesDatas")
    .ReturnsCollection<BoConsolidatedData>()
    .Parameter<int>("ReqId")
    .Required();

You can do this using the same modelbuilder you use to register your other OData resources.

Upvotes: 1

Related Questions