Solved

pass js array to asmx c# method

Posted on 2014-07-25
9
485 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now