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 8418481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:20:42+00:00 2026-06-10T02:20:42+00:00

I can’t seem to unpack a string list from a JSONResult. Here is the

  • 0

I can’t seem to unpack a string list from a JSONResult.

Here is the controller:

    [HttpPost]
    public JsonResult GetDescriptions(string incomingProjectName)
    {
        List<string> result = new List<string>();
        using (SFEntities ctx = new SFEntities())
        {
            result = (from ct in ctx.SF_CLIENT_TASK
                      join cp in ctx.SF_CLIENT_PROJECT on ct.PROJECT equals cp.ID
                      where cp.NAMEX == incomingProjectName
                      select ct.DESCRIPTION).ToList();
        }

        return Json( result );
    }

And here is my ajax method:

    $.ajax({
        type: "POST",
        url: "Home/GetDescriptions",
        contentType: "application/json; charset=utf-8",
        data: '{incomingProjectName : "projName"}',
        dataType: "json",
        success: function (msg) {
            alert("msg: " + msg);  // [Object object]
            alert("msg: 2 string: " + msg.toString);    // function toString() { [native code] }
            var list = eval(msg);
            alert("list: " + list); // blank
            alert("list to string: " + list.toString);  // function toString() { [native code] }
            alert("list data: " + list.valueOf);    // valueOf() { [native code] }
            alert("msg[0]: " + msg[0]);     // undefined
            alert("list[0]: " + list[0]);   // undefined
        },
    });

In the debugger I can see the contents of result has a long list of items, but I don’t seem them however I try to access it in the JavaScript.

Is there some kind of de-serialize or extract method I’m failing to call?

EDIT: This seems like it should be a boilerplate thing, but I haven’t been able to google many examples of doing this for some reason …

EDIT: Here is my final (working) code:

    $.ajax({
        type: "POST",
        url: "Home/GetDescriptions",
        data: { incomingProjectName: projName },
        success: function (msg) {
            alert( "msg: " + msg );
        },
        error: function (msg) {
            alert("Failed: " + msg.status + ": " + msg.statusText);
        }

And here is the controller code:

    public JsonResult GetDescriptions(string incomingProjectName)
    {
        List<string> result = new List<string>();
        using (SFEntities ctx = new SFEntities())
        {
            result = (from ct in ctx.SF_CLIENT_TASK
                      join cp in ctx.SF_CLIENT_PROJECT on ct.PROJECT equals cp.ID
                      where cp.NAMEX == incomingProjectName
                      select ct.DESCRIPTION).ToList();
        }

        return Json( result );
    }
  • 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-06-10T02:20:44+00:00Added an answer on June 10, 2026 at 2:20 am

    I’ve tested your code with the following controller method and it worked without any problems.

    public JsonResult Test()
    {
        return Json(new List<string> {"a", "b"},JsonRequestBehavior.AllowGet);
    }
    

    And the JS code:

    $.ajax({
        type: "POST",
        url: "Home/Test",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            console.log("msg: " + msg);  // [Object object]
            console.log("msg: 2 string: " + msg.toString);    // function toString() { [native code] }
            var list = eval(msg);
            console.log("list: " + list); // blank on your code
            console.log("list to string: " + list.toString);  // function toString() { [native code] }
            console.log("list data: " + list.valueOf);    // valueOf() { [native code] }
            console.log("msg[0]: " + msg[0]);     // undefined on your code
            console.log("list[0]: " + list[0]);   // undefined on your code
        }
    });
    

    And the result of the success method:

    msg: a,b
    msg: 2 string: function toString() { [native code] }
    list: a,b
    list to string: function toString() { [native code] }
    list data: function valueOf() { [native code] }
    msg[0]: a
    list[0]: a
    

    I believe the problem is that your list is empty or there is a problem with the serializer. Try to see the Json results contents on debug mode.

    Update:

    To see the data returning from your controller action, please remove the [HttpPost] attribute and change your return statement to return Json( result ,JsonRequestBehavior.AllowGet); on your code Then go to http://yoursite/controllername/GetDescriptions?incomingProjectName=projName to see the returning json.

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

Sidebar

Related Questions

Can we put functions to determine the condition for our list comprehensions. Here is
Does anyone know how can I replace this 2 symbol below from the string
Can you cast a List<int> to List<string> somehow? I know I could loop through
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can any one tell, how to get the result of LINQ query contains group
Can we change the default action of the edit selected row button? Here is
Can anybody shed some light on getDay() in Javascript please. Here datepicker is textbox
Can anybody tell what is the best(easy) way to sort the following string 'index'
Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can anyone help, how to retrieve exactly 2nd row from the table in oracle?

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.