Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change .cshtml View and see the changes instantly using .NET Core?

Context

In my .NET Framework 4.x ASP.NET MVC projects, when using the Visual Studio IDE, it was possible to edit a .cshtml view, save, then press ctrl+F5 in the browser and see the change immediately.

This seems to be no longer work in ASP.NET Core applications (using Visual Studio 2019 and .NET Core 3 Preview 5).

Question

Is this feature missing in ASP.NET Core? Is this a preview issue? Or am I missing something?

like image 945
g.pickardou Avatar asked May 08 '19 13:05

g.pickardou


People also ask

Which is better razor pages or MVC?

From the docs, "Razor Pages can make coding page-focused scenarios easier and more productive than using controllers and views." If your ASP.NET MVC app makes heavy use of views, you may want to consider migrating from actions and views to Razor Pages.

How do I move from one view to another in MVC?

In Mobile JS, you can transfer from one view to another view by using App. transferPage method. To achieve this, set the page url '/controllername/viewname' (here it's given as /Home/Ajax) as the second parameter of App.

Is .NET core better than previous MVC?

The primary difference between ASP.NET MVC and ASP.NET Core is their cross-platform approach. ASP.NET Core can be used on Windows, Mac, or Linux, whereas ASP.NET MVC can only be used for applications on Windows.

Can you mix razor pages and MVC?

You can add support for Pages to any ASP.NET Core MVC app by simply adding a Pages folder and adding Razor Pages files to this folder. Razor Pages use the folder structure as a convention for routing requests.


1 Answers

This is something that is no longer enabled by default as of ASP.NET Core 3, but it can be re-enabled as documented here:

Runtime compilation is enabled using the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package. To enable runtime compilation, apps must:

  • Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.

  • Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation:

     services
         .AddControllersWithViews()
         .AddRazorRuntimeCompilation();
    
like image 51
Kirk Larkin Avatar answered Sep 19 '22 21:09

Kirk Larkin