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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:21:06+00:00 2026-05-23T10:21:06+00:00

I am attempting to take the Name and ID fields from each object, but

  • 0

I am attempting to take the Name and ID fields from each object, but the fields are appearing undefined.

function OnHistoricalListBoxLoad(historicalListBox) {
    $.getJSON('GetHistoricalReports', function (data) {
        historicalListBox.trackChanges();
        $.each(data, function () {
            var listBoxItem = new Telerik.Web.UI.RadListBoxItem();
            listBoxItem.set_text(this.Name);
            listBoxItem.set_value(this.ID);
            historicalListBox.get_items().add(listBoxItem);
        });
        historicalListBox.commitChanges();
    });
}

[AcceptVerbs(HttpVerbs.Get)]
public JsonResult GetHistoricalReports()
{
    List<HistoricalReport> historicalReports = DashboardSessionRepository.Instance.HistoricalReports;

    var viewModel = historicalReports.Select(report => new
    {
        ID = report.ID,
        Name = report.Name
    }).ToArray();

    return Json(viewModel, JsonRequestBehavior.AllowGet);
}

I know that I am returning the data successfully, and I know that there is valid data. I am new to MVC/JavaScript, though.. I checked case sensitivity to ensure that I wasn’t making just an easy mistake, but it does not seem to be the issue. Am I missing something more complex?

Inspecting the HTTP Response JSON tab in Chrome I see:

0: {ID:1, Name:PUE}
1: {ID:2, Name:Weight}
2: {ID:3, Name:Power Actual vs Max}
3: {ID:4, Name:Power Actual}

  • 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-23T10:21:07+00:00Added an answer on May 23, 2026 at 10:21 am

    No idea, but passing such behemoth domain models to views is very bad practice. This is so kinda domain polluted that it has nothing to do in a view. In a view you work with views models. View models contain only what a view needs. In this case your view needs an ID and a Name. So pass a view model with only those single simple properties to this view:

    [AcceptVerbs(HttpVerbs.Get)]
    public JsonResult GetHistoricalReports()
    {
        var reports = DashboardSessionRepository.Instance.HistoricalReports;
        var reportsViewModel = reports.Select(x => new
        {
            ID = x.ID,
            Name = x.Name
        }).ToArray();
        return Json(reportsViewModel, JsonRequestBehavior.AllowGet);
    }
    

    Now, not only that you will save bandwidth, but you will get some clean JSON:

    [ { ID: 1, Name: 'Foo' }, { ID: 2, Name: 'Bar' }, ... ]
    

    through which you will be able to loop using $.each.


    UPDATE:

    Now that you have shown your JSON data it seems that there is a Content property which represents the collection. So you need to loop through it:

    $.each(data.Content, ...);
    

    and if you follow my advice about the view models your controller action would become like this:

    [AcceptVerbs(HttpVerbs.Get)]
    public JsonResult GetHistoricalReports()
    {
        var report = DashboardSessionRepository.Instance.HistoricalReports;
        var reportsViewModel = report.Content.Select(x => new
        {
            ID = x.ID,
            Name = x.Name
        }).ToArray();
        return Json(reportsViewModel, JsonRequestBehavior.AllowGet);
    }
    

    and now loop directly through the returned collection:

    $.each(data, ...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to take 4-5 fields from a large django form and display them
I am probably attempting to take URL Canonicalization a bit too far but here
I'm attempting to take values from a XML file and put them into a
I attempting to take a response from a REST service that queries an instance
I'm attempting to take large (huge) images (from a digital camera), and convert them
I'm attempting to take a string value from a Combo box then pass it
I am attempting to develop a class with a function that can take a
I'm attempting to put together a makefile that will take source files from a
I am attempting to take an object structured like so public class Item {
I am attempting to take an image captured from the rear camera, apply a

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.