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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:16:59+00:00 2026-06-01T13:16:59+00:00

In my ASP.net C# code, I have an IEnumerable container filled with objects of

  • 0

In my ASP.net C# code, I have an IEnumerable container filled with objects of an anonymous type (which is loosely based on data from SQL).

Suppose that my code looks something like this:

var uics = entities.getData()
    .Select(x => new
        {
            id = x.id
            name = x.name
            age = x.age
        });
return Json(uics); //Serialize JSON in ASP.net MVC 3

This is very simple. When I serialize this to JavaScript, I get an array of objects, each having fields id, name, and age.

What I would like to do is serialize this data to a JavaScript Object with id as the index, with each object referenced by its index having fields name and age.

How can I accomplish this.

  • 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-01T13:17:00+00:00Added an answer on June 1, 2026 at 1:17 pm

    You can create an IDictionary and use it as the result of the action:

    var uics = entities.getData()
        .ToDictionary(x => x.id, x => new { x.name, x.age });
    
    return Json(uics); //Serialize JSON in ASP.net MVC 3
    

    There is no need to explicitly specify the property names for the anonymous type used here, because the compiler defaults those to the name of the property used to provide a value (which in both cases here is the same).

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

Sidebar

Related Questions

I have some C# / asp.net code I inherited which has a textbox which
I have ASP.Net code similar to the following (this is inside a FIELDSET): <ol>
I have ASP.Net code generating my button's HTML for me using divs to get
We have some legacy ASP.NET code that detects if a request is secure, and
I have following asp.net code but it gives error when I change dropdown selected
I have a line of C# in my ASP.NET code behind that looks like
I'm an asp.net newbie. I have inherited a base of asp.net mvc code and
I'm using an Ajax update panel and have recently added ASP.NET tracing code to
I have asp.net generated html code. I want execute jQuery click function when user
My application is in Asp.Net MVC3 coded in C#.Net. I have Views which contains

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.