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

  • Home
  • SEARCH
  • 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 7903559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:46:31+00:00 2026-06-03T09:46:31+00:00

I have UsersClass which will never have more then 10 items. How can I

  • 0

I have UsersClass which will never have more then 10 items. How can I display user class with table in view something like this?

I want to show two rows with 10 cells

  • 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-03T09:46:33+00:00Added an answer on June 3, 2026 at 9:46 am

    As always and in every ASP.NET MVC application I recommend using a view model which is adapted to the requirements of the view. So in this view you mentioned a table in which you want to group those users by 5 elements per row:

    public class MyViewModel
    {
        public int Key { get; set; }
        public IEnumerable<UsersClass> Users { get; set; }
    }
    

    and then in the controller action:

    public ActionResult Index()
    {
        // that's your domain model => a list of UsersClass
        // could be coming from wherever you want
        var users = Enumerable.Range(1, 7).Select(x => new UsersClass
        {
            Id = x
        });
    
        // Now let's group those users into the view model:
        // We will have 5 elements per row
        var model = users
            .Select((u, index) => new { User = u, Index = index })
            .GroupBy(x => x.Index / 5)
            .Select(x => new MyViewModel
            {
                Key = x.Key,
                Users = x.Select(y => y.User)
            });
        return View(model);
    }
    

    and finally the strongly typed view is pretty trivial:

    @model IEnumerable<MyViewModel>
    <table>
        @foreach (var item in Model)
        {
            <tr>
                @foreach (var user in item.Users)
                {
                    <td>@user.Id</td>
                }
    
                <!-- That's just to fill the row with the remaining
                     td if we have less than 5 users. Obviously
                     depending on your requirements you could use
                     a single td with a calculated colspan or something else
                -->
                @for (int i = item.Users.Count(); i < 5; i++)
                {
                    <td></td>
                }
            </tr>
        }
    </table>
    

    Obviously this view could be simplified even further using display templates:

    @model IEnumerable<MyViewModel>
    <table>
        @Html.DisplayForModel()
    </table>
    

    and in the corresponding display template:

    @model MyViewModel
    <tr>
        @Html.DisplayFor(x => x.Users)
        @for (int i = item.Users.Count(); i < 5; i++)
        {
            <td></td>
        }
    </tr>
    

    and the UsersClass display template:

    @model UsersClass
    <td>@user.Id</td>
    

    and the result:

    enter image description here

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

Sidebar

Related Questions

I have a table called Users ( class User < ActiveRecord::Base ) and a
I have two classes: User : /** @Entity @Table(name=users) */ class User { /**
I have three tables: Project: ... relations: User: local: authorId foreign: id Users: class:
I need to create a table to store users' class schedules. These schedules have
I have User and Album models with HABTM relationship class Album < ActiveRecord::Base has_and_belongs_to_many
I have a model with a m2m relation to users: class SomeModel(models.Model): user=models.ManyToManyField(User,related_name='linked',blank=True,null=True) to
I have a C# class to store my User details and another for storing
I'm using Rails 3 with devise. I have a table books which has a
I have users class User < ActiveRecord::Base devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable attr_accessible
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs

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.