.cshtml更改后,为什么刷新后页面没有更新 [英] Why does page not update after refresh when .cshtml changes
问题描述
我正在尝试Blazor
,但我不明白为什么刷新浏览器页面后更改component
时它不会更新? client
是否应该像angular
那样更新自身?
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?
它仅在我重新启动blazor
服务器时刷新.
It only refreshes when i restart the blazor
server.
Index.cshtml
@page "/"
<h1>Hello, world!</h1>
如果我将<h1>
内的文本更改为Hello people
,则保存项目并刷新页面(如在Blazor
教程中建议的那样),我不应该看到Hello people
吗?
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 3.0之后,使用Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation程序包启用运行时编译. 要启用运行时编译,应用程序必须:
After Asp.net Core 3.0, Runtime compilation is enabled using the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package. To enable runtime compilation, apps must:
安装Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
NuGet软件包.
Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
NuGet package.
更新项目的Startup .ConfigureServices方法包括对AddRazorRuntimeCompilation的调用:
Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation:
services
.AddControllersWithViews()
.AddRazorRuntimeCompilation();
或
services.AddMvc().AddRazorRuntimeCompilation();
这篇关于.cshtml更改后,为什么刷新后页面没有更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!