Solved

pass js array to asmx c# method

Posted on 2014-07-25
9
476 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 76

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 76

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

13 Experts available now in Live!

Get 1:1 Help Now