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