.cshtml 更改时,为什么刷新后页面不更新 [英] Why does page not update after refresh when .cshtml changes

查看:46
本文介绍了.cshtml 更改时,为什么刷新后页面不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆