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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:20:12+00:00 2026-05-15T04:20:12+00:00

I have some viewdata that is generated by going through my repository to the

  • 0

I have some viewdata that is generated by going through my repository to the database to grab some scheduling info. When the information is stored in the Viewdata, I noticed that the viewdata is enumerated. How could I access the enumerated items and generate a table/list based on the viewdata? Most of the information just needs to be spit out into a table, but one item will have a link generated for it.

Thanks!

  • 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-15T04:20:13+00:00Added an answer on May 15, 2026 at 4:20 am

    I don’t know really understand what you mean when you say that the viewdata is enumerated. The ViewData contains instances of objects that you put inside your controller action. If you put an instance of an IEnumerable<T> you could enumerate. So let’s suppose that you store an IEnumerable<ProductViewData> inside your ViewData from the controller action that’s rendering the view:

    public ActionResult Index()
    {
        ViewData["products"] = new[]
        {
            new ProductViewData { Id = 1, Description = "product 1" },
            new ProductViewData { Id = 2, Description = "product 2" },
            new ProductViewData { Id = 3, Description = "product 3" },
        }
        return View();
    }
    

    Inside the view you could enumerate and generate a table:

    <table>
    <% foreach (ProductViewData product in (IEnumerable<ProductViewData>)ViewData["products"]) { %>
    <tr>
      <td><%= product.Id %></td>
      <td><%= Html.Encode(product.Description) %></td>
    </tr>
    <% } %>
    </table>
    

    That being said you, I would recommend you to never do this and always use strongly typed views. Using ViewData requires you to cast and use magic strings inside your views which IMHO is bad.

    Here’s the same using a strongly typed view:

    public ActionResult Index()
    {
        return View(new[]
        {
            new ProductViewData { Id = 1, Description = "product 1" },
            new ProductViewData { Id = 2, Description = "product 2" },
            new ProductViewData { Id = 3, Description = "product 3" },
        });
    }
    

    and the view:

    <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SomeNamespace.ProductViewData>" %>
    
    <table>
    <% foreach (var product in Model) { %>
    <tr>
      <td><%= product.Id %></td>
      <td><%= Html.Encode(product.Description) %></td>
    </tr>
    <% } %>
    </table>
    

    and things get even more promising when you start using HTML helpers in MVCContrib such as the Grid:

    <%= Html.Grid<ProductViewData>(Model)
        .Columns(column => {
            column.For(model => model.Id);
            column.For(model => model.Description);
        })
    %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dropdownlist that I populate with some stuff: In my controller ViewData[SourceModelList]
I want to have some viewData info across all my views so I am
I want all my pages to use have some viewdata. i need to get
I have some arbitrary pixel data that I want to save as a PNG.
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have some code that will change the background color of a specific label
i have some problems with a Query seem IN dosen't work with Group_concat, that
Greetings, I have an asp.net mvc application. I have some links that corresponds to
We have some images in our database and want to display their in view.
I have a view using a master page that contains some javascript that needs

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.