Why does page not update after refresh when .cshtml changes
asp.net CoreClient SideBlazorasp.net Core Problem Overview
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
?
asp.net Core Solutions
Solution 1 - asp.net Core
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();
Solution 2 - asp.net Core
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.
Solution 3 - asp.net Core
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();
Solution 4 - asp.net Core
do the following:
-
Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation from NuGet.
-
Update the ConfigureServices method in the Startup class to look like below:
services.AddControllersWithViews().AddRazorRuntimeCompilation();
- You good to go.
Solution 5 - asp.net Core
If you go into Tools > Options > Keyboard and search in the "Show commands containing" search box search for "BrowserLink". Find the option that says "OtherContextMenus.BrowserLink.RefreshLinkedBrowsers" by default this is set to CTRL+Alt+Enter. Click "Remove" and then select the "Press Shortcut Keys" input and press Ctrl+S. Next (just to the left of the input) change Use new shortcut in "Global" to be "Text Editor". Click "Ok" until the window has closed. Now Visual Studio shares CTRL+S with both Saving files and Refreshing linked browsers.
(This will only work if your text editor .cshtml, .css, .js, etc. files in the edit window are the active selections) WARNING: if you don't set it to something other than global then it will override the shortcut for Save and you won't be able to save your files.