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.
Do you have multiple ParentViews in your Model? If not then you can just have
Then reference your Class Attributes as