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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:00:36+00:00 2026-05-29T15:00:36+00:00

I want to return an array of strings from an MVC function via a

  • 0

I want to return an array of strings from an MVC function via a jQuery AJAX call.

My client side code is:

function get_categories() {
    var url = "/Profile/GetCharacters";
    $.post(url, function (data) {
    alert(data);
});

But I cannot read array elements. In alert(data) it always says system.array[]
and in alert(data[0]) it says s (i.e. first character in system.array[]) and not the array elements.

Here is simplified version of my server side code.. cause original is big way too complicated 🙂

public Array GetCharacters()
    {

        var ret = new string[10];
        ret[0]="abc";
        ret[1] = "def";
        ret[2] = "ghi";
        return (ret);
    }

but this gives “System.string[]” instead and same problem when accessing individual values

  • 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-29T15:00:37+00:00Added an answer on May 29, 2026 at 3:00 pm

    You can return JSON.

    For instance, you could make an Ajax request to the following controller action:

    public JsonResult GetMyData()
    {
        SomeClass s = new SomeClass();
        s.Property1 = "value";
        s.Property2 = "another value";
    
        return Json(s, JsonRequestBehavior.AllowGet); //you will need the AllowGet option to return data to a GET request
    }
    

    Then, your javascript could make an Ajax request (using jQuery’s Ajax function) to the controller:

    var onSuccess = function (data) {
        //data will be your s object, in JSON format
    };
    
    $.ajax({
        type: 'GET',
        url: '/ControllerName/GetMyData/',
        success: function (data) { onSuccess(data); }
    });
    

    EDIT: When returning an array, or List you will need to add the traditional:true option to the Ajax call, like this:

    var onSuccess = function (data) {
        //data will be your s object, in JSON format
    };
    
    $.ajax({
        type: 'GET',
        url: '/ControllerName/GetMyData/',
        success: function (data) { onSuccess(data); },
        traditional: true
    });
    

    I am not 100% sure why (I Iam sure someone will fill us in), but that has given me fits in the past.

    One more EDIT: You may need to parse the JSON, which should create an actual javascript Array object for you:

    var onSuccess = function (data) {
        //data will be your s object, in JSON format
        var arr = JSON.parse(data);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to return a set of values from function till the point they
I'm looking for a function that finds a substring from an array of strings
I have an array of strings that I want to extract specific content from:
I made a code that translate strings to match each word from the array
I want to return an array of Strings in the form abc#xyz#ghi#tru (where #
I received 10 name strings from mysqldb to $.Ajax (function(data) now how to split
I am trying to return mime types from an array. I have these strings
I want a simple function that receives a string and returns an array of
I want to return a private field from a remoted object but i get
I want to return some errors to my jquery method. What is happening is

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.