Problem

How to reuse parts of web pages using partial views in ASP.NET Core MVC.

Solution

In an empty project update Startup class to add services and middleware for MVC,

  1. public void ConfigureServices(
  2. IServiceCollection services)
  3. {
  4. services.AddMvc();
  5. }
  6. public void Configure(
  7. IApplicationBuilder app,
  8. IHostingEnvironment env)
  9. {
  10. app.UseMvc(routes =>
  11. {
  12. routes.MapRoute(
  13. name: "default",
  14. template: "{controller=Home}/{action=Index}/{id?}");
  15. });
  16. }