Why does page not update after refresh when .cshtml changes

You should add or enable runtime compilation in razor pages,

Install-Package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation -Version 3.1.6

After installing set the startup file as ,

 services.AddMvc().AddRazorRuntimeCompilation();

I guess you are running the app with the debugger connected? this prevents the recompilation. You need to:

Press Ctrl-F5 to run the app without the debugger. Running with the debugger (F5) isn't supported at this time.

https://github.com/dotnet/aspnetcore/issues/5456


After Asp.net Core 3.0, Runtime compilation is enabled using the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package. To enable runtime compilation, apps must:

Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.

Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation:

services
    .AddControllersWithViews()
    .AddRazorRuntimeCompilation();

or

services.AddMvc().AddRazorRuntimeCompilation();