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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:36:35+00:00 2026-06-12T04:36:35+00:00

I am creating a model which is intended to hold a table. The table

  • 0

I am creating a model which is intended to hold a table. The table will hold an arbitrary number of rows defined at run-time. I am wondering if there’s an easy way to define this in MVC?

Currently all I have is:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CableSolve.Web.Models.Orders.ActivityDetailsModel>" %>

<div id="ActivityDisplay">
    <table id="ActivitiesGrid">
    </table>
    <div id="ActivitiesGridPager"></div>
</div>

In a different model, I create a table which had a static number of rows. This was pretty easy:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CableSolve.Web.Models.Orders.OrderDetailsModel>" %>

<fieldset class="collapsible">
    <legend>
        <%= Html.DisplayFor(model => model.OrderDetailsLegendName)%>
    </legend>
    <table id="OrderDetailsContentTable" class="ContentTable">
        <tr>
            <td><%= Html.DisplayFor(model => model.OrderID.Name)%></td>
            <td><%= Html.DisplayFor(model => model.OrderID.Value)%></td>

            <td><%= Html.DisplayFor(model => model.Comment.Name)%></td>
            <td><%= Html.DisplayFor(model => model.Comment.Value)%></td>
        </tr>
        ...

So, any ideas on how I could go about having an arbitrary number of rows in ActivitiesGrid?

Basically, my controller is going to get some information at run-time and I want to display the retrieved information in a table, but I do not know how many rows of information I am going to receive.

As a light-weight solution without introducing third-party stuff (for now, if it proves necessary I will):

public class ActivityDetailsModel
{
    public List<ActivityRow> ActivityRows = new List<ActivityRow>();

    public struct ActivityRow
    {
        public DateTime? Date;
        public string Person;
        public string OrderOrTaskID;
        public string Activity;

        public ActivityRow(DateTime? date, string person, string orderOrTaskID, string activity)
        {
            Date = date;
            Person = person;
            OrderOrTaskID = orderOrTaskID;
            Activity = activity;
        }
    }

    public ActivityDetailsModel(IEnumerable<Activity> activities)
    {
        foreach(Activity activity in activities)
        {
            string orderOrTaskID = activity.TaskID != 0
                                     ? activity.OrderID + "-" + activity.TaskID
                                     : activity.OrderID.ToString();

            string activityDescription = string.Format("OldValue: {0}, NewValue: {1}", activity.OldValue,
                                                       activity.NewValue);

            ActivityRows.Add(new ActivityRow(activity.UpdateDateTime, activity.UpdateUsername, orderOrTaskID, activityDescription));
        }
    }
}

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CableSolve.Web.Models.Orders.ActivityDetailsModel>" %>

<div id="ActivityDisplay">
    <table id="ActivitiesGrid">
        <%foreach (var activityRow in Model.ActivityRows)
          {%>
            <tr>
                <td><%= Html.DisplayForModel(activityRow.Date)%></td>
                <td><%= Html.DisplayForModel(activityRow.Person)%></td>
                <td><%= Html.DisplayForModel(activityRow.OrderOrTaskID)%></td>
                <td><%= Html.DisplayForModel(activityRow.Activity)%></td>
            </tr>
          <%}%>
    </table>
    <div id="ActivitiesGridPager"></div>
</div>

Is this relatively understandable? I hate the mark-up with all the angle-brackets and percent signs, but the project hasn’t been developer with the alternative syntax.

  • 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-06-12T04:36:36+00:00Added an answer on June 12, 2026 at 4:36 am

    Since you’re after something dynamic, you can take advantage of existing helpers like MVC WebGrid helper or even MvcContrib Grid. These helpers will take care of generating a table containing the columns you want. There’s no need to write the table by hand since it’ll be dynamically generated during runtime according to the number of objects present in your datasource.

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

Sidebar

Related Questions

I have a jQuery Model windows which contains a form. On creating of the
When creating a Business Model in which layer (GUI, BLL, DAL) entities class must
I use Entity framework for creating model. I have table hierarchy where User is
I'm using acts_as_nested_set on a model which is called node. There are multiple lists
I'm developing a model which holds configuration settings for server options. The number and
I'm creating a timeclock application where there is a ClockPunch NSManagedObject model with properties
I am creating an edit form for an Event data model in which the
I fetch the latest 5 rows from a Foo model which is ordered by
In my Rails 3 app, I am creating a Book model which contains an
I'm creating a barButton which when pressed should set the editing mode of a

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.