11

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

SunilK
  • 147
  • 1
  • 9
  • This should not happen with a default asp.net mvc app, especially running within Visual Studio. Are you messing with the headers in any way? Check your layout view, does it have any meta tags that might be caching requests? – mxmissile Sep 10 '14 at 22:12
  • Ctrl-F5 did not work I tried Marko's suggestion already. It did not work. I've also tried disabling cache in web.config. Nothing seems to work. What is even more weird is that another application that does not user Razor does work when adding markup and refreshing. – SunilK Sep 11 '14 at 01:31
  • @mxmissle, checked layout view, no meta tags, also I send back pragma no cache. It still insists on caching the page – SunilK Sep 11 '14 at 01:46

2 Answers2

20

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();
Ian Gibblet
  • 552
  • 3
  • 18
  • 1
    The issue described in the question is not for ASP.NET Core but for ASP.NET. `What I'm using: asp.net 4.5, IISExpress, visual studio 2013.` – Thangadurai Nov 01 '19 at 11:00
  • 1
    Spot on man! Using Net core and saved me lots of time. Thanks. Have to say, this problem also apply to the 16.3.10 version of VS 2019. – netfed Nov 27 '19 at 00:15
  • question clearly states its for Visual Studio 2013. – Mark Worrall Feb 06 '20 at 14:22
-6

Try hitting CTRL+F5 on the web page. The old files may be cached by your browser.

See this question for more details: Get rid of [dynamic] JavaScript views in Visual Studio

Community
  • 1
  • 1
Zain Rizvi
  • 23,586
  • 22
  • 91
  • 133
  • You can also try closing all your browser tabs and then starting the debugger. Just in case you cache isn't being cleared out otherwise for some reason – Zain Rizvi Sep 11 '14 at 18:20
  • Caching was not the problem here since in the question, it was stated that caching was already disabled. – Ian Gibblet Dec 16 '19 at 13:23