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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:23:25+00:00 2026-05-29T13:23:25+00:00

Edit: Seems numerous people think this is a dumb idea, so I would appreciate

  • 0

Edit: Seems numerous people think this is a dumb idea, so I would appreciate an explanation of why it’s bad? I was trying to make one partial view that could handle a list of any models to display in table format. I was planning on extending it then to allow also take config options to say what columns to display and add extra ones after I figured out the basics. Is there a better way to do this?

How does one use a list of expando objects in views? I am trying to make a view that can display a table format of a list of any of my models, and it looks like expando object is a good fit for this, but I can’t figure out how to get the iterations properly.

I tried using these links: Dynamic Anonymous type in Razor causes RuntimeBinderException, ExpandoObject, anonymous types and Razor but they seem either incomplete or not what what I am doing.

Here is my view:

@using System.Reflection
@model IList<dynamic>

<h2>ExpandoTest</h2>
@if(Model.Count > 0)
{
    <table>
        @foreach (dynamic item in Model)
        {
            foreach(var props in typeof(item).GetProperties(BindingFlags.Public | BindingFlags.Static))
            {
                <tr>
                    <td>
                        @props.Name : @props.GetValue(item, null)
                    </td>
                </tr>
            }

        }
    </table>
}

My controller:

public ActionResult ExpandoTest()
    {
        IList<dynamic> list =
            EntityServiceFactory.GetService<UserService>().GetList(null, x => x.LastName).ToExpando().ToList();

        return View(list);
    }

Extension method:

 public static IEnumerable<dynamic> ToExpando(this IEnumerable<object> anonymousObject)
    {
        IList<dynamic> list = new List<dynamic>();

        foreach(var item in anonymousObject)
        {
            IDictionary<string, object> anonymousDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(item);
            IDictionary<string, object> expando = new ExpandoObject();
            foreach (var nestedItem in anonymousDictionary)
                expando.Add(nestedItem);

            list.Add(expando);
        }

        return list.AsEnumerable();
    }

The list of expando items are being properly created I can see through debugging, but in the view it says item can not be resolved in the typeof(item) statement and throws the error saying type item cannot be found. If I try item.GetType().GetProperties() that returns nothing. Now I understand that these don’t work because the type is dynamic, but how can I dynamically display the properties and values then?

  • 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-29T13:23:26+00:00Added an answer on May 29, 2026 at 1:23 pm

    You can cast a ExpandoObject to an IDictionary, and do something like this:

    foreach(var prop in item as IDictionary<string, object>)
    {
        <tr>
            <td>
                @prop.Key
                @prop.Value
            </td>
        </tr>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like such a simple question. I have several Edit boxes on my
EDIT - there are no blank lines. EDIT 2 - my bad, it seems
Edit: Seems like Facebook finally fixed this bug! Could you help me understand why
Edit: [Solved] : It seems that the getTableCellRendererComponent of the CustomTableCellRenderer is called every
[edit] So it seems my code works fine, another piece of code + tiredness
Which algorithms or data structures are used in auto-suggest features? It seems that edit-distance
It seems it allows you to edit the content of an element, but what
EDIT : I completely re-wrote the question since it seems like I was not
[EDIT] Based on feedback yes, VS2010 seems to support SL4 Library TDD despite a
Whenever I edit files on emacs, it seems a temporary file is created with

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.