Solved

pass js array to asmx c# method

Posted on 2014-07-25
9
518 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 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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
LVL 78

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 78

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

726 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