Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3974854
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:37:01+00:00 2026-05-20T04:37:01+00:00

I get an error of Cannot convert object of type System.String’ to type ‘System.Collections.Generic.List’1[…+ContactHolder]’

  • 0

I get an error of “Cannot convert object of type System.String’ to type ‘System.Collections.Generic.List’1[…+ContactHolder]'”

This is my C# code:

public class ContactHolder{
    public String Name { get; set; }
    public String Address { get; set; }
}

[WebMethod]
public static string AddContact(Object items){
    List<ContactHolder> contacts = new JavaScriptSerializer().ConvertToType<List<ContactHolder>>(items);
    return String.Format("You added {0} contacts!", contacts.ToString());
}

This is my Javascript code (note I have included jquery-1.4.1.js and json2.js in my project)

function Test() {
var arr = new Array();
var contact = new Object();
contact.Name = "Ben";
contact.Address = "Ohio";

var contact2 = new Object();
contact.Name = "Jon";
contact.Address = "Illinois";

arr[1] = contact;
arr[2] = contact2;

var DTO = JSON.stringify(arr);
PageMethods.AddContact(DTO, OnMyMethodComplete);}

function OnMyMethodComplete(result, userContext, methodName) {alert(result);}

When I pass DTO into myPageMethod it looks like this: “[{“Name”:”Ben”,”Address”:”Ohio”},{“Name”:”Jon”,”Address”:”Illinois”}]”

When it appears in my WebMethod as items it looks like this: “[{\”Name\”:\”Ben\”,\”Address\”:\”Ohio\”},{\”Name\”:\”Jon\”,\”Address\”:\”Illinois\”}]”

The code errors on the call to JavaScriptSerializer().ConvertToType, the message is {“Cannot convert object of type System.String’ to type ‘System.Collections.Generic.List’1[…+ContactHolder]'”}

What do I need to do to make this work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:37:02+00:00Added an answer on May 20, 2026 at 4:37 am

    Passing parameter to WebMethod with jQuery Ajax

    Remove JSON.stringify or do like this:

    sending JSON object successfully to asp.net WebMethod, using jQuery

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the error Cannot implicitly convert type 'string' to 'System.Web.HtmlString' when I attempt
I get an error in the bellow code it says I cannot convert method
I continue to get this error: Object '%s' cannot be renamed because the object
I sometime get following error message: Cannot convert the value in attribute 'Color' to
The following code gives me the errors: Cannot implicitly convert type T to string.
In the below sql statement i get the following error Cannot use an aggregate
I tend to get errors such as: Fatal error: Cannot redeclare get_raw_data_list() (previously declared
I cannot figure out why I get this error during check-in. I checked in
I cannot run NCover. I get the error: NCover couldn't create a coverage report
When trying to compile my class I get an error: The constant 'NamespaceName.ClassName.CONST_NAME' cannot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.