刷新视图而不重新启动应用程序
Refresh View without restarting application
我曾经能够对 ASP.NET(核心)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();
我曾经能够对 ASP.NET(核心)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();