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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:48:03+00:00 2026-06-10T00:48:03+00:00

So I have a json that calls a JsonResult The class: public class Client{

  • 0

So I have a json that calls a JsonResult

The class:

public class Client{
    public int Id {get;set;}
    public string Name {get;set;}
}

The action being called:

public JsonResult Index(int Id)
        {
      var a = context.Clients.ToList();
      return Json(a, JsonRequestBehavior.AllowGet);
}

this is the call

<script type="text/javascript">
    $(document).ready(function () {
        var link;
        $('a.client-list').click(function () {
            link= $(this);
            $.ajax({
                url: '/client/index?Id=4455',
                dataType: 'json',
                success: function (data) {
                    $.each(data, function (id, val) {
                        alert(id.toString() + ' ' + val.toString());
                    });
                }
            });
            return false;
        });
    });
    </script>

So my problem is, I know that it returns something cuz it loops through the alert that I put in. but the value that pops out is this

0 [object Object]
1 [object Object]

I’m not sure why it’s not reading it properly. The values queried btw are

1 TestCompany1
2 TestCompany2

Am I missing something on the jquery??

  • 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-10T00:48:04+00:00Added an answer on June 10, 2026 at 12:48 am

    Update your $.each like so:

    $.each( data, function (index, client ) {
        alert( client.Id + ' ' + client.Name );
    });
    

    You are returning a collection (Array) of the Client type. The $.each function will provide the index of the array and the item in the array associated with the index. In this case, each item in the array will be a Client Object. More information on $.each here: http://api.jquery.com/jQuery.each/

    Fore more details when debugging JavaScript, try using the console:

    $.each(data, function ( index, client ) {
        console.log( client );
    });
    

    Just hit F12 in your browser (PC) and select the console tab. You will be able to see more detail about the Object including its properties.

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

Sidebar

Related Questions

I have a set of radio buttons that are dynamically generated (via JSON call):
I have JSON string that has nested objects with dynamic names that vary each
I have a JSON string that I would like to include as a value
I have a json file that I'm trying to get values out of. One
I have a BSjax class that I wrote that lets me make async calls
I have a .NET MVC controller action that returns a JsonResult to a YUI
Hi I have this as one of my controllers: [HttpPost] public JsonResult GetPinPoints(string Id)
I have an action method in my UpdatesController with the following signature: public JsonResult
I have a basic JsonResult method that is being called by a jQuery $.ajax
I have a WCF service that takes as a parameter a string value name.

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.