The MVC framework is an ASP.NET Core application framework built around the Model–View–Controller pattern. It separates application concerns into models, views, and controllers while keeping HTTP requests and HTML visible to the developer. It began as an alternative to Web Forms, whose desktop-style development model could produce unwieldy web projects. In ASP.NET Core, MVC runs on an open, extensible, cross-platform foundation. section 1.1.1 section 19.4
For HTML responses, a controller can define multiple action methods and choose a view while processing a request. A view can also use private or shared partial views. That flexibility is useful for complex features, but not every page needs it: Razor Pages tie markup and C# code together for a more focused approach. The two approaches can coexist. section 23.2
Listing 5.2 Enabling MVC in the Program.cs file in the LanguageFeatures folder
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
var app = builder.Build();
//app.MapGet("/", () => "Hello World!");
app.MapDefaultControllerRoute();
app.Run();
A basic Program.cs setup registers controller-and-view services with AddControllersWithViews(), then maps a default controller route with MapDefaultControllerRoute(). Both statements are needed to turn a minimal web-project configuration into this MVC setup. section 5.1.2
MVC controllers can also provide RESTful web services without using views. For that setup, register services with AddControllers() and map controller routes with MapControllers(). Keeping related operations in a controller avoids repeating response-handling steps across individual endpoints in Program.cs. section 19.4 section 19.4.1
MVC is useful, not compulsory. Single-page applications have reduced the need to organize every web application around server-rendered MVC views, although MVC can still support them through web services. Razor Pages offer less initial preparation for focused features; MVC remains a flexible choice when those features become more complex. section 1.1.1 section 23.2
