Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does page not update after refresh when .cshtml changes

I am trying out Blazor and i do not understand why when changing a component after refreshing the browser page it does not update ? Shouldn't the client update itself similar to how angular does?

It only refreshes when i restart the blazor server.

Index.cshtml

@page "/"  <h1>Hello, world!</h1> 

If i change lets say the text inside the <h1> to Hello people , i save the project and i refresh the page ( as i am advised in the Blazor tutorial) shouldn't i see Hello people ?

like image 557
Bercovici Adrian Avatar asked Jan 09 '19 08:01

Bercovici Adrian


People also ask

Can you mix MVC and Razor pages?

You can add support for Pages to any ASP.NET Core MVC app by simply adding a Pages folder and adding Razor Pages files to this folder.

What is razor runtime compilation?

Build-time and publish-time compilation of Razor files is enabled by default by the Razor SDK. When enabled, runtime compilation complements build-time compilation, allowing Razor files to be updated if they're edited.


1 Answers

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();   
like image 94
Eureka Avatar answered Sep 26 '22 05:09

Eureka