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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:48:57+00:00 2026-05-10T19:48:57+00:00

Into some view data i have put the result of an anonymous type: var

  • 0

Into some view data i have put the result of an anonymous type:

            var projectData = from p in db.Projects                           orderby p.title                           select new                           {                               Title = p.title,                               DevURL = p.devURL ?? 'N/A',                               QAURL = p.qaURL ?? 'N/A',                               LiveURL = p.liveURL ?? 'N/A',                               Users = p.GetUsers().MakeUserList()                           };          ViewData['ProjectSummary'] = projectData; 

How do I iterate through this view data in the MVC view on the front end to say, make a table of results?

  • 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. 2026-05-10T19:48:58+00:00Added an answer on May 10, 2026 at 7:48 pm

    In your case it would be much simpler to create a model to hold your data rather than using an anonymous type.

    The issue you’re having is that your anonymous type is cast to an object when its stored within the ViewData. On the UI side, when you get that object out, the only way to access its properties is to use reflection. You do NOT want to do this in your UI. It will be highly ugly. Instead, just add the following class to your Models:

    public class Project{  public string Title {get;set;} public string DevUrl {get;set;} public string QAUrl {get;set;} public string LiveUrl {get;set;} public IEnumerable<User> Users {get;set;}  public static IEnumerable<Project> RetrieveAllProjects() {   return from p in db.Projects            orderby p.title            select new Project              {                 Title = p.title,                 DevURL = p.devURL ?? 'N/A',                 QAURL = p.qaURL ?? 'N/A',                 LiveURL = p.liveURL ?? 'N/A',                 Users = p.GetUsers().MakeUserList()              }; } 

    In your controller do this:

    public ActionResult Index() {   return View('Index', Project.RetrieveAllProjects()); } 

    and in your view’s codebehind, strongly type it thusly:

    //snip public partial class Index : ViewPage<IEnumerable<Project>> { //snip 

    You might think its a bit wasteful to have all these models laying around, but its much easier to understand, and makes your UI code much slimmer, if you use your models wisely.

    Also, a model is a great place (and, in fact, should be where you do it) to place the logic for loading your data and constructing the models themselves. Think ActiveRecord. And, while you’re coding all this, realize that projects like SubSonic create your models for you without any muss or fuss.

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

Sidebar

Related Questions

I want to load some data from mysql into my cocoa application view before
Looking for some direction here as I'm running into some migration problems. We have
I'd really like to get into some D3D coding, but I don't have the
I have a UIViewController that manages the display of some data. When the user
I have some data that's currently stored in an Excel workbook. It makes sense
I'm looking into some possible options for unit testing C++ classes. So, short and
Im trying to get into some basic JavaFX game development and I'm getting confused
I'm currently running into some issues resizing images using GD. Everything works fine until
I recently introduced HTML into some RSS feeds that I publish (which up to
I'm running into some little glitch on Internet Explorer. The site looks like it

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.