Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Razor views are not updating when simply updating html

ASP.NET Razor views are not updating when simply updating html. I'm trying to add a few elements on a page when my application is running in debug mode, and the changes are not being seen in the browser when I refresh the page. However, if I stop and restart the application, the changes are seen.

I've tried disabling cache, sending back headers (pragma no-cache), shift reload on the browser, nothing seems to work.

This is quite frustrating having to continually bounce the app.

What I'm using: asp.net 4.5, IISExpress, visual studio 2013.

Does anyone know how to turn off the output cache so I can debug without having to restart the entire application?

thanks

like image 221
SunilK Avatar asked Sep 10 '14 21:09

SunilK


1 Answers

As of September 2019, there's a bug in visual studio which prevents razor views from updating unless you restart the server after every update. Very annoying!

To fix:

1- Add the NuGet package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation

2- Modify the ConfigureServices method in startup.cs

Replace

 services.AddControllersWithViews();

with

 services.AddControllersWithViews().AddRazorRuntimeCompilation();
like image 140
Ian Gibblet Avatar answered Nov 15 '22 15:11

Ian Gibblet