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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:41:48+00:00 2026-05-26T02:41:48+00:00

Hi in a Action I create Json data like so: public JsonResult InvoiceLineGridData(string sidx,

  • 0

Hi in a Action I create Json data like so:

public JsonResult InvoiceLineGridData(string sidx, string sord, int page, int rows, int id)
         {
            ....

                var jsonData = new {
                total = totalPages,
                page,
                records = totalRecords,
                rows = invoiceLines.Select(............)
            };
            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }

In the method that calls this I want to get the number of records from this data.

Could this be a problem because it’s an anonymous type?

I go :

var result = controller.InvoiceLineGridData(null, "desc", 1, 10, 7);

result.Data

but I can’t seem to get the total number of records out. Anybody know how to do 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-05-26T02:41:49+00:00Added an answer on May 26, 2026 at 2:41 am

    Yes, this is because Data is just an object. If you are doing this in the same assembly as your controller, you could create a dynamic and get the data from it. But your best bet, if you’re actually hoping to use data this way, is to create a real (non-anonymous) type to which you can cast the Data in your test method.

    var jsonData = new InvoiceLineData {
                Total = totalPages,
                Page,
                Records = totalRecords,
                Rows = invoiceLines.Select(............)
            };
    
    
    var resultData = (InvoiceLineData)result.Data;
    // or
    dynamic resultData = result.Data;
    
    Assert.AreEqual(10, resultData.Records);
    

    As I look at this more, it looks like your data is probably following a specific pattern expected by some kind of general grid control. You would do well to formalize this in a GridData class and use that.

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

Sidebar

Related Questions

I have a create action like so in a rails controller: def create @user
I am trying to create controller actions which will return either JSON or partial
If i have a controller action Create that returns a view with the following
in my MVC application I have a controller (ProjectController) which has an action (create).
I have a create action for a form that potentially generates errors (i.e. first
If I render the update action from inside the create action, is there a
I'm using the VS2008 installer (plus a custom Orca action) to create an installer
I need to upload an image as part of a create action in an
I want to create an Action to automate GCJ compilation. Since I couldn't make
I have an SQL table written in MSSQL: create table [action] ( action_id bigint

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.