.NET Core MVC 页面在更改后不刷新

编程入门 行业动态 更新时间:2024-10-27 17:09:55
本文介绍了.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 的清空缓存和硬重新加载"以及其他浏览器都无济于事.这发生在使用 Visual Studio for Mac 和 VS Code 的 Windows 和 Mac 上

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 中进行了更改(我找不到关于此更改的任何公告).如果您没有在开发"环境中明确运行,则编译 Razor 视图,您将看不到对 .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

但是,您可以使用 Startup 类中的一些配置关闭此功能,如下所示.

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 页面在更改后不刷新

本文发布于:2023-11-13 21:55:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页面   NET   Core   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!