3

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);

2 Answers 2

3

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.

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

1 Comment

Due the link samples... seem there were a need for implementation of Composite Key Handler, if you want to call it like that...
2

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.

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.