When using the debugger, it was showing that the increments were being made. It seems the issue is when the webpage is being built. Are you referring to the webpage as "render code"? Here is that where is just add a new row to show totalrecords.
<h2>List of Movies</h2>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Year</th>
<th>Format</th>
<th>Length</th>
<th>Video</th>
<th>Audio</th>
</tr>
</thead>
<tbody>
@foreach(var item in Model.ListMovies)
{
<tr>
<td>"@item.Title"</td>
<td>@item.Year</td>
<td>@item.Format</td>
<td>@item.Length</td>
<td>@item.Video</td>
<td>@item.Audio</td>
</tr>
<tr>
<td>@item.totalRecordsRead</td>
</tr>
}
</tbody>
</table>
I also have it defined as public Int as follows:
public class IndexModel : PageModel
{
public List<MovieInfo> ListMovies = new List<MovieInfo>();
public int totalRecordsRead;
private object? movieinfo;
public void OnGet()
{
try
{
String connectionString = "Data Source=XPSSLOWPC;Initial Catalog=Movies;Integrated Security=True;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
String sql = "select Title, Year, Format, Length, Video, Audio from Info where Format = 'Ultra HD' or Format = 'Blu-ray' or Format = 'DVD' order by Title";
using (SqlCommand command = new SqlCommand(sql, connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
MovieInfo movieinfo = new MovieInfo();
{
movieinfo.Title = reader.GetString(0);
movieinfo.Year = reader.GetString(1);
movieinfo.Format = reader.GetString(2);
movieinfo.Length = reader.GetString(3);
movieinfo.Video = reader.GetString(4);
movieinfo.Audio = reader.GetString(5);
};
ListMovies.Add(movieinfo);
totalRecordsRead = ListMovies.Count + 1;
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.ToString());
}
}
}
public class MovieInfo
{
public String? Title;
public String? Year;
public String? Format;
public String? Length;
public String? Video;
public String? Audio;
public int totalRecordsRead;
}