asp.net-mvc - 如何在 Rider 中启用 View 热重载?

标签 asp.net-mvc asp.net-core .net-core rider

这个问题在这里已经有了答案:





.NET Core MVC Page Not Refreshing After Changes

(14 个回答)


2年前关闭。




我正在使用 Rider 编写一个 MVC 应用程序,一个行为困扰着我:当我修改 View 时,我必须重建解决方案并重新启动它以查看更改。当我从浏览器重新加载网站时,是否可以直接看到修改后的 View ?

顺便说一句,IDE(或 dotnet?)不认为 View 更改是重建触发更改。我必须手动单击“重建选定项目”,然后才能启动应用程序的修改版本。这是为什么?

最佳答案

这不是 Rider 的问题,它基本上是 ASP.NET MVC Core 的工作原理。您需要启用 Razor runtime compilation .从文档(强调我的):

Razor files are compiled at both build and publish time using the Razor SDK. Runtime compilation may be optionally enabled by configuring your application.



请注意,默认情况下运行时不包含在此列表中。要更改此行为:
  • 添加 Nuget 包 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation .
  • 更改您的 Startup.ConfigureServices包含运行时编译的代码:
    services
        .AddControllersWithViews()
        .AddRazorRuntimeCompilation();
    
  • 关于asp.net-mvc - 如何在 Rider 中启用 View 热重载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58300922/

    相关文章:

    .net - 如何在不调用每个项目的情况下让 dotnet build 选择正确的框架?

    .net - 将发布配置文件从 Azure Web 应用导入 Visual Studio Code(或 vs for mac)

    c# - 如何在 ConfigureServices .Net Core 3.1 中注册具有多个接口(interface)的服务并将该服务用作单个实例

    asp.net - 如何将 .ASPX 页面重定向到 .NET Core Razor 页面

    c# - 如何部署像 EF 的 Scaffold-DbContext 这样提供 Powershell 命令的 Nuget 包?

    c# - 从日期选择器的下拉列表中禁用日期

    asp.net-mvc - 将 Unity 与 Windows Azure 结合使用 : An attempt was made to access a socket in a way forbidden by its access permissions

    c# - 如何处理复选框列表?

    c# - 从客户端应用程序调用 Web API

    c# - 库 NuGet 配置无效