Вопрос

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