Alexander Zeitler
Alexander Zeitler

Reputation: 13089

Refresh View without restarting application

I used to be able to make changes to an ASP.NET (Core) MVC View and just hit refresh in the browser to apply the HTML (or Razor) changes.

Starting with ASP.NET Core 3.0 it seems I always have to restart the MVC application to get the latest changes in my browser.

This is my application configuration

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?}");
    });
}

Upvotes: 14

Views: 6273

Answers (1)

Alexander Zeitler
Alexander Zeitler

Reputation: 13089

Adding the NuGet package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation to the project and changing this line fixed it:

services.AddControllersWithViews().AddRazorRuntimeCompilation();

Upvotes: 29

Related Questions