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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:50:02+00:00 2026-05-24T08:50:02+00:00

I have a simple Action that iterates around a dbset does a bit of

  • 0

I have a simple Action that iterates around a dbset does a bit of manipulation on each record then returns the chosen records via json, a bit like this:

List<JsonResult> dataout = new List<JsonResult>();
foreach(var r in db.People.OrderBy("something")) {
    // do stuff to the rec
    string SubmittersName = rec.Submitter.Name;
    dataout.Add(this.Json(new { rec.Created, rec.Name, SubmittersName,  
                     OtherStuff }));
}

return new JsonResult() {
    Data = dataout.Select(r=>r),
    ContentEncoding = Encoding.UTF8,
    JsonRequestBehavior = JsonRequestBehavior.AllowGet
};

To me it seems a bit clumsy, but its easy to follow whats going on.

(Also in the returned json I get ContentEncoding:null which seems a bit strange given that I specified it)

How could this be improved on?

General sugesstions/comments appreciated.

TIA.

  • 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-24T08:50:03+00:00Added an answer on May 24, 2026 at 8:50 am

    You’re misusing JsonResult.

    JsonResult isn’t a way to store JSON data; it’s simply a way to return JSON data from a view.
    You shouldn’t create a list of them.

    By returning JSON from a collection of JsonResults, you’re actually converting the JsonResults to JSON, including their ContentEncoding properties (which you never set).

    Instead, you can directly return a collection of anonymous types:

    return Json(
        db.People.OrderBy(something).Select(rec => new { rec.Created, ... }),
        JsonRequestBehavior.AllowGet
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really simple action in a controller that simply returns a view
If I have a controller action that returns a simple view return View(Index); Is
I have an HttpPost controller action that takes in a simple form DTO object.
I have a fairly simple Action in an MVC3 application that should render an
I would like to have controller GET action that returns a JSON-serialized dictionary. The
I have a simple create action that save a product to DB. after saving
i wish to have a simple Action in my controller that accepts a few
I have a Action that sends a simple email: [HttpPost, ActionName(Index)] public ActionResult IndexPost(ContactForm
I have a simple C++ DLL that implements a few custom actions for a
I have a simple email address sign up form as follows: <form action= id=newsletterform

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.