0

I am converting some of my services to Web API2 and I have some functions which take 2 or 3 parameters. How are those routing attributes constructed?

When I call the function from the old service in javascript its

data: { "symboltype": symboltype, "symbol": symb, "requestDate": dDate}

I've tried the following routing attribute among other variations, which dont work

    <HttpGet()> _
    <Route("getsinglerangeprojection/{symboltype:int,symbol,requestdate}")> _
    Public Function GetSingleRangeProjection(ByVal symboltype As Integer,
                                             ByVal symbol As String,
                                             ByVal requestDate As String) As ProjectedRange
        ...code here
    End Function

2 Answers 2

2

the answer is they all get separated by slashes as shown below

 <HttpGet()> _
 <Route("getsinglerangeprojection/symboltype/{symboltype:int}/symbol/{symbol}/requestdate/{requestDate:datetime}")> _
 Public Function GetSingleRangeProjection(ByVal symboltype As Integer,
                                         ByVal symbol As String,
                                         ByVal requestDate As String) As ProjectedRange
    ...code here
 End Function
Sign up to request clarification or add additional context in comments.

Comments

0

You should create a model to represent your data like this

public class MyData
    {
        public string symboltype { get; set; }

        public string symbol { get; set; }

        public DateTime requestData { get; set; }
    }

And change your method to use the model or JObject as the parameter.

Finally, post the whole json object as a string

data:JSON.stringify({ "symboltype": symboltype, "symbol": symb, "requestDate": dDate});

Hope this help.

2 Comments

The javascript works fine as is, that wasn't the question. The question is how to specify multiple parameters in attribute routing
Apparently, you couldn't reach the API method. If you don't like that approach, you can you a query string like localhost:3557/api/…

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.