Click here to Skip to main content
15,896,320 members

How to send bi-dimensional array from angular js to web API

H.AL asked:

Open original thread
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;
Tags: AngularJs, WebAPI2

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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