Razor Pages and Entity Framework

  • Thread starter Thread starter bobthornley
  • Start date Start date
B

bobthornley

Guest
I am using ASP.NET Razor pages with Entity Framework for a web application (I am new to both of these technologies.)

I am working on a page that will display 10 tables all coming from the same SQL database table. In the code behind for this page, I have created 10 different data sets. This all works okay on my page.

The view code for each table is identical, but I can’t figure out how to efficiently set up my page so that I am not repeating the view code 10 times. Here is a sample of the code that will display each table:


<table class="table table-striped hidden-xs">
<tbody>
@foreach (var item in Model.SLSQLDatabase1Context)
{
<tr>
<td>
@Html.DisplayFor(model => item.Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)<br />
@Html.DisplayFor(modelItem => item.Reference)
</td>
</tr>
}
</tbody>
</table>


The only thing I need to change each time is the Model. So instead of Model. SLSQLDatabase1Context, I need to reference a different dataset each time.

How can I do this? Any help will be appreciated.

Continue reading...
 
Back
Top