Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two solutions running on my desktop: One is a web solution using angularjs and calling the other solution which is a web API based on MVC and both are written in vb.net. Everything is working perfectly except one thing: when I tried to send a bi-dimensional I got below error:

The request is invalid. The parameters dictionary contains an invalid entry for parameter 'myBiDimenArray' for method 'System.Web.Http.IHttpActionResult Calculate(System.String[,], Int32)' in 'CustomAPI.TestController'. The dictionary contains a value of type 'System.String[]', but the parameter requires a value of type 'System.String[,]'."


Below is my code in angular js:

var myBiDimenArray = [
            [1, 6],
            [5, 2],
            [9, 10]
            ];

console.log(myBiDimenArray); // it logs the array correctly

return $http({
            method: "GET",
            url: urlBase + "Calculate",   
            params: {
                myBiDimenArray: myBiDimenArray,
                intSize: 1,
            },
            headers: {
                'Content-Type': 'application/json',
                'X-ApiKey': 'test' ,
                'Authorization': 'Basic 123456'
            }
        });


Below is my code in Web APi:

<HttpGet>
    Public Function Calculate(<FromUri> ByVal myBiDimenArray(,) As String, <FromUri> ByVal intSize As Integer) As IHttpActionResult
  ....
 End Function


Any suggestions?

I am new to this, I have searched for how to create Bi-Dimen Array in vb.net and in JavaScript so I implemented the above in my solutions but error 400 is thrown and method is even not accessed.


Update:

Please note that this is my route in webAPi config file:

config.Routes.MapHttpRoute( _
 name:="Test_Calculate", _
 routeTemplate:="api/{controller}/{action}/{myBiDimenArray}/{intSize}", _
 defaults:=New With {.controller = "Test", .action = "Calculate"} _
)


Could it be a configuration problem?

What I have tried:

I have changed the web APi method to this:
<HttpGet>
    Public Function Calculate(<FromUri> ByVal myBiDimenArray()() As String, <FromUri> ByVal intSize As Integer) As IHttpActionResult
  ....
 End Function


The method could be accessed, myBiDimenArray length was 3 (which is correct), but each array inside was acting like a String, example: "[1,6]" : 1 parameter instead of being 2 params inside an array;
Posted
Updated 27-Nov-17 19:03pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900