Alexander Zeitler

Alexander Zeitler

Refresh ASP.NET Core MVC view without reloading the application

Published on Wednesday, December 11, 2019

After doing no ASP.NET (Core) stuff for while, today I created an ASP.NET Core MVC 3.0 application using dotnet new mvc.

I started the application using dotnet watch run and I was surprised to see the whole application restarting even when I just changed a single character within a MVC View e.g. ./Views/Home/Index.cshtml.

The solution was to add this NuGet package to the project:

Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation

In the Startup.cs I had to change this line:

public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}

to this

public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews()
.AddRazorRuntimeCompilation();
}

Now the application doesn't have to restart for simple HTML/Razor content changes.

Happy coding 😉

What are your thoughts about "Refresh ASP.NET Core MVC view without reloading the application"?
Drop me a line - I'm looking forward to your feedback!
Imprint | Privacy