ASP.NET Core MVC Explained
Ad
What is ASP.NET Core MVC?
MVC (Model-View-Controller) is a pattern for building web apps that separates data (Model), UI (View), and logic (Controller). ASP.NET Core MVC is Microsoft's implementation.
The Three Parts
- Model — your data and business logic.
- View — the HTML (Razor templates).
- Controller — handles requests, returns views.
A Controller
public class HomeController : Controller {
public IActionResult Index() {
var products = _service.GetAll();
return View(products); // passes model to view
}
}
A Razor View
@model List<Product>
<ul>
@foreach (var p in Model) {
<li>@p.Name - $@p.Price</li>
}
</ul>
Routing
// /Home/Index maps to HomeController.Index()
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
FAQs
MVC vs Razor Pages vs Web API?
MVC for complex apps, Razor Pages for page-focused sites, Web API for JSON backends. More in our .NET section.
What is Razor?
A templating syntax that mixes C# with HTML using @.
