问题
在ASP.NET Core 3.0中,对Razor页面修改刷新无法展示修改后的内容。
原因
这是由于在ASP.NET Core 3.0中,对Razor视图和Razor页面的运行时编译的支持被移到了单独的程序包中,没有默认启用Razor运行时编译。
解决方案
- 安装Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
- 在
Startup中启用Razor运行时编译:public class Startup { public Startup(IConfiguration configuration, IWebHostEnvironment env) { Configuration = configuration; Env = env; } public IWebHostEnvironment Env { get; set; } public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { IMvcBuilder builder = services.AddRazorPages(); //仅在调试时才启用运行时编译 #if DEBUG if (Env.IsDevelopment()) { builder.AddRazorRuntimeCompilation(); } #endif } }
Reference
- [Discussion] Breaking changes to runtime compilation for Razor views and Razor Pages
- Razor file compilation in ASP.NET Core
- .cshtml change does not show on page refresh in ASP.NET Core 3
最后
以上就是潇洒战斗机最近收集整理的关于ASP.NET Core 3.0 Razor 修改页面刷新无效Reference的全部内容,更多相关ASP.NET内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复