更改后.NET Core MVC页面不刷新 [英] .NET Core MVC Page Not Refreshing After Changes

查看:804
本文介绍了更改后.NET Core MVC页面不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在最新版本2.2上构建.NET Core MVC。更改CSHTML文件并刷新页面时出现问题,我的更改未反映在浏览器中。我必须重新启动项目才能看到我的更改。现在已经发生了一段时间,所以我不确定是什么原因引起了这个问题。

I'm building a .NET Core MVC on the latest version 2.2. I have a problem when I make changes to the CSHTML file and refresh the page, my changes are not reflected in the browser. I have to restart the project in order to see my changes. This has been happening for a while now so I'm not exactly sure what change caused this issue.

我尝试使用Chrome浏览器的空缓存和硬重载以及其他浏览器都无济于事。

I've tried using the chrome's "Empty Cache and Hard Reload" as well as other browsers to no avail. This happens on Windows and Mac using both Visual Studio for Mac and VS Code

在默认的.Net Core项目中,它可以正常工作,因此必须在我的项目中有所更改一路上。我想知道从哪里开始才能调试此问题?我尝试注释掉 Startup.cs Program.cs 中的几乎所有内容,但没有解决方案。

In a default .Net Core project it works fine so it must be something in my project that changed along the way. I'm wondering where I need to start in order to debug this issue? I've tried commenting out almost everything in my Startup.csand Program.cs with no resolution.

推荐答案

ASP.NET Core 2.2似乎有所更改(而且我找不到有关此更改的任何公告。 )。如果您未明确在开发环境中运行,则将编译剃刀视图,并且不会看到对.cshtml

There was a change made in ASP.NET Core 2.2 it seems (and I can't find any announcements about this change). If you are not explicitly running in the 'Development' environment then the Razor Views are compiled and you will not see any changes made to the .cshtml

所做的任何更改。您可以关闭

You can however turn off this using some config in your Startup class as follows.

services.AddMvc().AddRazorOptions(options => options.AllowRecompilingViewsOnFileChange = true);

对于ASP.NET Core 3.0及更高版本,请参见Alexander Christov的答案

For ASP.NET Core 3.0 and higher, see Alexander Christov's answer.

这篇关于更改后.NET Core MVC页面不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆