.NET Core MVC Page Not Refreshing After Changes

后端 未结 10 448
花落未央
花落未央 2020-12-04 10:09

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 br

相关标签:
10条回答
  • 2020-12-04 10:33

    Using .net core 2.2 running app with command dotnet watch run the project is restarted after every change

    0 讨论(0)
  • 2020-12-04 10:36

    There are two ways to resolve this issue:

    1. Check the permissions of folder in which your .sln file present.There may be a problem with file access permissions as Visual studio may not be to access files when IIS express server is running, so to reflect new .cshtml changes each time you need to restart the server,so I suggest edit the folder access permissions by:

    Right click on folder->properties->security->click on edit button -> check all options->save.

    Restart Visual studio to see changes.

    If this does not work then use 2 option.

    2.In your project in startup.cs file add this below line ConfigureServices() in method :

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

    0 讨论(0)
  • 2020-12-04 10:42

    In ASP.NET Core 3.0 and higher, RazorViewEngineOptions.AllowRecompilingViewsOnFileChangeis not available.

    Surprised that refreshing a view while the app is running did not work I discovered the following solution:

    1. Add Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package to the project
    2. Add the following in Startup.cs:

      services.AddControllersWithViews().AddRazorRuntimeCompilation();

    Here's the full explanation for the curious...

    HTH

    0 讨论(0)
  • 2020-12-04 10:42

    I've just created a new project using the latest ASP.NET MVC Core 3.1 template and I altered the following to get runtime recompilation enabled for Debug:

    Reference NuGet package - Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.

    Startup.cs - ConfigureServices(IServiceCollection services) WAS:

    // stuff...
    
    services.AddControllersWithViews();
    
    // more stuff...
    

    NOW:

    // stuff...
    
    var mvcBuilder = services.AddControllersWithViews();
    
    #if DEBUG
        mvcBuilder.AddRazorRuntimeCompilation();
    #endif
    
    // more stuff...
    
    0 讨论(0)
提交回复
热议问题