title: How to display data from multiple tables/models in a single cshtml in asp.net core .NET6 (Razor pages)
body: <p>I am new to asp.net core razor pages. I need to display data from multiple tables on a single page. I can only access one model class from the page. Can you please help me figure out how can I have access to multiple tables from a single page (cshtml).</p>
  <p>I need to display User_Profile (Table/model) in Class-&gt; create.cshtml (Class is attached to Class table by default).
  Following is the code from Class -&gt; create.cshtml</p>
  <pre><code> @page
  @model TestProject.Pages.Class.CreateModel
  
  @{
      ViewData[&quot;Title&quot;] = &quot;Create&quot;;
      Layout = &quot;~/Pages/Shared/_Layout.cshtml&quot;;
  }
  
  
  &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;col-md-4&quot;&gt;
          &lt;form method=&quot;post&quot;&gt;
              &lt;div asp-validation-summary=&quot;ModelOnly&quot; class=&quot;text-danger&quot;&gt;&lt;/div&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  @*&lt;label asp-for=&quot;Class.ID&quot; class=&quot;control-label&quot;&gt;&lt;/label&gt;
                  &lt;input asp-for=&quot;Class.ID&quot; class=&quot;form-control&quot; /&gt;*@
                  @*&lt;label asp-for=&quot;User_Profile.ID&quot; class=&quot;control-label&quot;&gt;&lt;/label&gt;
                  &lt;select asp-for=&quot;User_Profile.ID&quot; class=&quot;form-control&quot; &gt;
                      &lt;option value=&quot;&quot;&gt;Select Student&lt;/option&gt;
                      &lt;option value=&quot;Female&quot;&gt;Female&lt;/option&gt;
                      &lt;option value=&quot;Male&quot;&gt;Male&lt;/option&gt;
                  &lt;/select&gt;
                  &lt;span asp-validation-for=&quot;Class.ID&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;*@
              &lt;/div&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;label asp-for=&quot;Class.Description&quot; class=&quot;control-label&quot;&gt;&lt;/label&gt;
                  &lt;input asp-for=&quot;Class.Description&quot; class=&quot;form-control&quot; /&gt;
                  &lt;span asp-validation-for=&quot;Class.Description&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
             
              
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;input type=&quot;submit&quot; value=&quot;Create&quot; class=&quot;btn btn-primary&quot; /&gt;
              &lt;/div&gt;
              &lt;table class=&quot;table&quot;&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.userprofile[0].FirstName)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.userprofile[0].LastName)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.userprofile[0].ProfileType)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.userprofile[0].Status)
              &lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
  @foreach (var item in Model.User_Profile) {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.FirstName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.LastName)
              &lt;/td&gt;
              &lt;td&gt; 
                  @Html.DisplayFor(modelItem =&gt; item.ProfileType)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Status)
              &lt;/td&gt;
             
              
          &lt;/tr&gt;
  }
      &lt;/tbody&gt;
  &lt;/table&gt;
  
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  
  @section Scripts {
      @{await Html.RenderPartialAsync(&quot;_ValidationScriptsPartial&quot;);}
  }
  </code></pre>
  <p>I am getting the error where I am writing  Model.User_profile. For example:</p>
  <pre><code>@foreach (var item in Model.User_Profile) 
  </code></pre>
  <p>I would really appreciate your help.</p>
  <p>Thank you!</p>