Asp.net-Core-3.1
在不重新啟動應用程序的情況下刷新視圖
我曾經能夠對 ASP.NET (Core) MVC 視圖進行更改,只需在瀏覽器中點擊刷新即可應用 HTML(或 Razor)更改。
從 ASP.NET Core 3.0 開始,似乎我總是必須重新啟動 MVC 應用程序才能在瀏覽器中獲取最新更改。
這是我的應用程序配置
public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseStaticFiles(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
將 NuGet 包添加
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation到項目並更改此行修復它:services.AddControllersWithViews().AddRazorRuntimeCompilation();