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

  • Home
  • SEARCH
  • 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 7584693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:59:01+00:00 2026-05-30T18:59:01+00:00

ISSUE: I have an asp.net mvc 3 app. I’m using EF 4.1 and trying

  • 0

ISSUE:

I have an asp.net mvc 3 app. I’m using EF 4.1 and trying out jqGrid. I’m trying to get data for my jqGrid using the GridData method below. I get the following error on the group of data starting at ‘var jsonData = new…’. Any ideas?

ERROR:

{“The array type ‘System.String[]’ cannot be initialized in a query result.
Consider using ‘System.Collections.Generic.List`1[System.String]’ instead.”}

GridData Method:

    public JsonResult GridData(string sidx, string sord, int page, int rows)
    {                        
        var result = from a in db.t_harvest_statistics_elk
                     where a.year == "2008" && a.unit_number == 1
                     orderby a.id
                     select a;


        int pageIndex = Convert.ToInt32(page) - 1;
        int pageSize = rows;
        int totalRecords = result.Count();   // context.Questions.Count();
        int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

        var questions = result.Skip(pageIndex * pageSize).Take(pageSize);

        var jsonData = new
        {
            total = totalPages,
            page,
            records = totalRecords,
            rows = (
                from question in questions
                select new
                {
                    i = question.id,                                                
                    cell = new string[] { SqlFunctions.StringConvert((double)question.id), SqlFunctions.StringConvert((double)question.total_rec_days), question.year }

                }).ToArray()
        };

        return Json(jsonData);
    }

HERE IS AN EXAMPLE THAT DOES WORK

public JsonResult DynamicGridData(string sidx, string sord, int page, int rows)
    {
        var context = new HaackOverflowDataContext();
        int pageIndex = Convert.ToInt32(page) - 1;
        int pageSize = rows;
        int totalRecords = context.Questions.Count();
        int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

        var questions = context.Questions.OrderBy(sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize);

        var jsonData = new
        {
            total = totalPages,
            page,
            records = totalRecords,
            rows = (
                from question in questions
                select new
                {
                    i = question.Id,
                    cell = new string[] { question.Id.ToString(), question.Votes.ToString(), question.Title }
                }).ToArray()
        };
        return Json(jsonData);
    }
  • 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-30T18:59:03+00:00Added an answer on May 30, 2026 at 6:59 pm

    The easiest way to fix the code will be to use something like the following

    // to be able to use ToString() below which is NOT exist in the LINQ to Entity
    // so we should get the data from the database and save the result locally before
    // the next step. One can use .ToList() or to .AsEnumerable(), but one should
    // choose only the fields of questions which we will need later
    var queryDetails = (from item in questions
                        select new { item.id, item.total_rec_days, item.year }).ToList();
    var jsonData = new {
            total = totalPages,
            page,
            records = totalRecords,
            rows = (
                from question in queryDetails
                select new
                {
                    id = question.Id,
                    cell = new [] {
                        question.Id.ToString(),
                        question.total_rec_days.ToString(),
                        question.year.ToString()
                    }
                }).ToArray()
        };
    return Json(jsonData, JsonRequestBehavior.AllowGet);
    

    Your current code contain some small problems like the usage of i = question.id instead of id = question.id.

    I would recommend you to read the answer and download the demo from the answer which contains more recent and extended code.

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

Sidebar

Related Questions

I have a relatively simple ASP.net MVC 2 app that is using SubSonic. Everything
In my ASP.NET MVC 3 app I have the pager enabled on my jqGrid,
i have an asp.net mvc app and i am trying to move all of
I'm building a grid in ASP.NET MVC and I have the following issue: Above
I have got one weird issue. I am working on an asp .net mvc
I have an ASP.NET MVC App, which use EF code First, for some reason
I'm building a multi-tenant app with ASP.NET MVC and have a problem with validating
i have an asp.net mvc app that has a form that uploads a file.
In an ASP.NET MVC app, I have code that boils down to the following:
I have TinyMCE working great in my ASP.NET MVC app except for the spellchecker.

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.