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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:20:33+00:00 2026-06-17T00:20:33+00:00

I have these 3 classes: public class Product { public int ProductId { get;

  • 0

I have these 3 classes:

 public class Product 
     {
            public int ProductId { get; set; }
            public int ClassId { get; set; }
            public string Name { get; set; }
            public virtual Class Class { get; set; }
        }



public class Partner
    {
        public int PartnerId { get; set; }
        public int ClassId { get; set; }     
        public string Name { get; set; }
        public virtual Class Class { get; set; }
    }



public class Price
    {
        public int PriceId { get; set; }
        public int ClassId { get; set; }
        public int ProductId { get; set; }
        public int PartnerId { get; set; }
        public float Cost { get; set; }
    }

and I have 3 lists of data:

List<Product> products; List<Partner> partners; List<Price> prices;

How can I show partners in top row, products in left column and price (if it is available for each partner and product) in cells of table in MVC View?

  • 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-17T00:20:35+00:00Added an answer on June 17, 2026 at 12:20 am

    As always I would start by designing a view model that will reflect the requirements of the view:

    public class MyViewModel
    {
        public IEnumerable<Product> Products { get; set; }
        public IEnumerable<PartnerPricesViewModel> PartnerProductPrices { get; set; }
    }
    
    public class PartnerPricesViewModel
    {
        public string PartnerName { get; set; }
        public IEnumerable<Price> Prices { get; set; }
    }
    

    and then I will populate this view model in the controller action from our domain models and pass it to the view:

    public ActionResult Index()
    {
        List<Product> products = ...
        List<Partner> partners = ...
        List<Price> prices = ...
    
        var model = new MyViewModel
        {
            Products = products,
            PartnerProductPrices =
                from partner in partners
                select new PartnerPricesViewModel
                {
                    PartnerName = partner.Name,
                    Prices = 
                        from product in products
                        select prices.FirstOrDefault(price => 
                            price.PartnerId == partner.PartnerId && 
                            price.ProductId == product.ProductId
                        )
                }
        };
    
        return View(model);
    }
    

    and finally I will have a corresponding strongly typed view to the view model:

    @model MyViewModel
    
    <table>
        <thead>
            <tr>
                <th></th>
                @foreach (var product in Model.Products)
                {
                    <th>@product.Name</th>
                }
            </tr>
        </thead>
        <tbody>
            @foreach (var partner in Model.PartnerProductPrices)
            {
                <tr>
                    <td>@partner.PartnerName</td>
                    @foreach (var price in partner.Prices)
                    {
                        <td>
                            @if (price != null)
                            {
                                @price.Cost.ToString("c")
                            }
                            else
                            {
                                // There was no price found matching this 
                                // product and partner => we display an empty cell
                                @:&nbsp;    
                            }
                        </td>
                    }
                </tr>
            }
        </tbody>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these classes: public class Product { [Key] public virtual int ProductId {
Let's say we have these two classes: public class Base { public static int
I have two classes 'Product' and 'Seller'. public class Product { public int Id
I have the following class... public class Product { public int Id { get;
I have the following simple textbook classes defined: public class Product { public int
Concerning data binding I have these classes: public class Foo : List<Bar> { public
I have these two classes public class Person { } public class Company {
I have these classes in C# (.NET Framework 3.5) described below: public class Base
I have XNA game and it contains these classes public partial class Bird :
Hi every one I have these classe @Entity @Table(name = login, uniqueConstraints={@UniqueConstraint(columnNames={username_fk})}) public class

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.