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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:59:12+00:00 2026-05-23T06:59:12+00:00

I would like to use two models in one view. For that I have

  • 0

I would like to use two models in one view. For that I have the following set up.
In a single .cs file I have the following model code:

public class Class1   
{
   //List of atttributes 1.
}

public class Class2   
{
   //List of atttributes 2.
}


 public class ParentView
{
   public Class1 Class1{get; set;}
   public Class2 Class2{get; set;}

}

To make use of these two classes in one view I reference

@model IEnumerable<Project.Models.ParentView> 

in the View .cshtml page. and In my view code there is this code that is breaking up .. I get an error saying – “The models.parentview does not have a definition of Class1Attribute and no extension method…..etc..” How can I classify the statement below so that it recognizes the attribute.

@foreach (var item in Model)
  {

        @Html.DisplayFor(modelItem => item.Class1Attribute)

        @Html.DisplayFor(modelItem => item.Class1Atttribute)    


  }

thanks for your help.

  • 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-23T06:59:13+00:00Added an answer on May 23, 2026 at 6:59 am
    @Html.DisplayFor(modelItem => item.Class1.Class1Attribute)
    

    Do you have multiple ParentViews in your Model? If not then you can just have

    @model Project.Models.ParentView
    

    Then reference your Class Attributes as

    @Html.DisplayFor(modelItem => Model.Class1.Class1Attribute)
    @Html.DisplayFor(modelItem => Model.Class2.Class2Attribute) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For anything but trivial view models, I use a view model builder that handles
I would like to use a UISegmentedControl with two buttons as a replacement for
I would like to use CSS to present a two-column layout. The markup I
I would like to use a language that I am familiar with - Java,
I would like to use a component that exposes the datasource property, but instead
I have two models class Employer(models.Model): name = models.CharField(max_length=300, blank=False) id = models.IntegerField() status
Say that I have two models- Users and Accounts. Each account can have at
I have the user submit a single line (description) that must have one number
I have a model that for edit/update actions only is logically split into two
I'd like to use DTO's in my view models in lieu of my domain

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.