Solved

pass js array to asmx c# method

Posted on 2014-07-25
9
491 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
9 Comments
 
LVL 4

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 77

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 77

Accepted Solution

by:
arnold earned 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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