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
有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top