?
Solved

pass js array to asmx c# method

Posted on 2014-07-25
9
Medium Priority
?
532 Views
Last Modified: 2014-09-09
Hi all,

I am trying to pass a multi layered array in the form;

array[<string>, array[<string>, <string>]]

using ajax to a c# asmx method. I catch the element successfully like so;

public static bool UpdateSheet(List<object> updates)
{
...
}

Open in new window


and I cast as follows;

List<KeyValuePair<String, List<KeyValuePair<String, String>>>> current = (List<KeyValuePair<String, List<KeyValuePair<String, String>>>>)updates[i];

Open in new window


however its throwning an error any reasons why?

thanks in advance.
0
Comment
Question by:flynny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 5

Expert Comment

by:Chris Watson
ID: 40219013
What is the exception you're getting?
0
 

Author Comment

by:flynny
ID: 40219049
Internal Server Error:error:{"Message":"Unable to cast object of type \u0027System.Object[]\u0027 to type \u0027System.Collections.Generic.List`1[System.Collections.Generic.KeyValuePair`2[System.String,System.Collections.Generic.List`1[System.Collections.Generic.KeyValuePair`2[System.String,System.String]]]]\u0027.","StackTrace":"   at AdminFunctions.UpdateStyleSheet(List`1 updates)
0
 

Author Comment

by:flynny
ID: 40219066
sorry in fact looking at my code i think it should be as follows;

KeyValuePair<String, List<KeyValuePair<String, String>>> current = (KeyValuePair<String, List<KeyValuePair<String, String>>>)updates[i];

Open in new window


however, this is throwing the following error;


System.InvalidCastException
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 79

Expert Comment

by:arnold
ID: 40256237
The difficulty in analyzing what you are experiencing deals with the means by which the data is being passed. The method used to transfer data.

One option might be to pass the data as an xml stream/structure.
0
 

Author Comment

by:flynny
ID: 40257944
HI Arnold,

passing as xml would be an option could you provide an example of doing this?
0
 
LVL 79

Accepted Solution

by:
arnold earned 2000 total points
ID: 40258309
Your javascript will have to create the xml structure

Alternatively, you can use the data you have, but you have to parse convert the data versus relying on a function which does not seem suitable to the formatting you are using.
<array>
     <1>value</1>
     <2>value</>
</array>

There are several examples if you search for javascript xml to array and the reverse .

Your existing setup might be missing a single step to convert any URL or HTTP encoding which  could be the cause for the conversion error.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40311697
I've requested that this question be deleted for the following reason:

The question has either no comments or not enough useful information to be called an "answer".
0

Featured Post

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question