Varun Gupta
Varun Gupta

Reputation: 1457

Pass multiple parameters with OData URL

I want to pass multiple parameters in my Get Request using OData Protocol. Below is what I am doing.

I am using fiddler for GET request which is as follows

https://127.0.0.1/odata/controllerName('param1','param2')

In my controller class, I have two controller methods. First controller methods accepts only one parameter and second accepts two parameters. Controller method with one parameter works fine.When I am requesting controller method with two parameters, It invokes controller method with one parameter. I am not able to understand why it does not recognize controller method with two parameters. Or OData does not support multiple parameters.

Controller method 1

public int controllerName([FromOdataUri] string key);

Controller Method 2

public int controllerName([FromODataUri] string param1, [FromODataUri] string param2);

Upvotes: 3

Views: 29019

Answers (2)

Tan Jinfu
Tan Jinfu

Reputation: 3347

Per the OData protocol, if the key of entity composites of 2 properties, then you can query it in this way:

    ~/odata/EntitySet(key1='key1',key2='key2')

But if you don't have such key, then you may need Functions, which are called with GET, and the parameters are passed in in URL, such as

    ~/odata/Products(33)/Default.CalculateGeneralSalesTax(state='WA') 
    ~/odata/GetSalesTaxRate(state='CA')

please refer this sample: https://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/ODataFunctionSample/

you can add as much parameters as you want.

Upvotes: 3

Kyle Hale
Kyle Hale

Reputation: 8120

OData takes one parameter, but it can be a JSON dictionary passed as the request body. See the example here under the heading "Invoking the Action" and Google around for ODataActionParameters to see how .NET's WebAPI implements the OData parameter dictionary requirement.

Upvotes: 2

Related Questions