ASP.NET Core MVC Tutorial
Lesson 8 of 100 8% of course

Routing in ASP.NET Core MVC — Conventional and Attribute

1 · 6 min · 5/24/2026

Learn Routing in ASP.NET Core MVC — Conventional and Attribute in our free ASP.NET Core MVC Tutorial series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

Sign in to track progress and bookmarks.

Routing in ASP.NET Core MVC — Conventional and Attribute — ShopNest Enterprise MVC
Article 8 of 100 · Module 1: MVC Fundamentals · Product Catalog
Target keyword: routing asp.net core mvc · Read time: ~22 min · .NET: 8 / 9 · Project: ShopNest Enterprise MVC — Product Catalog

Introduction

Routing in ASP.NET Core MVC — Conventional and Attribute is essential for ASP.NET Core MVC developers building ShopNest Enterprise MVC — Toolliyo's 100-article enterprise learning platform covering products, orders, cart, payments, dashboard, and audit logs. Whether you target campus drives at TCS, Infosys, or Wipro, or build admin portals at product companies, this lesson delivers production-grade MVC depth.

In Indian delivery projects, teams lose sprints when juniors skip routing fundamentals — fat controllers, missing anti-forgery tokens, or domain entities leaked to Razor views. This article prevents that class of failure on Product Catalog.

After this article you will

  • Explain Routing in plain English and in technical MVC terms
  • Implement routing in ShopNest.Mvc (Product Catalog)
  • Compare the wrong approach vs the production-ready enterprise approach
  • Answer fresher and mid-level MVC interview questions confidently
  • Connect this lesson to Article 9 and the 100-article MVC roadmap

Prerequisites

Concept deep-dive

Level 1 — Analogy

Routing is the post office sorting room — the URL address determines which controller action handles the delivery.

Level 2 — Technical

Routing integrates with the ASP.NET Core MVC pipeline: register services in Program.cs, handle requests in controllers, render HTML via Razor views. On ShopNest Enterprise MVC this powers Product Catalog without coupling UI to database internals.

Level 3 — Architecture

[Browser] → [HTTPS/Kestrel] → [Middleware Pipeline]
  → [Routing] → [Controller Action] → [Service Layer]
  → [EF Core / Identity] → [Razor View Engine] → [HTML Response]

Common misconceptions

❌ MYTH: Routing is only needed for large enterprise apps.
✅ TRUTH: ShopNest Enterprise MVC starts simple — add complexity when traffic, team size, or compliance demands it.

❌ MYTH: ASP.NET MVC 5 and ASP.NET Core MVC are the same.
✅ TRUTH: Core MVC uses Kestrel, minimal hosting in Program.cs, and cross-platform deployment — MVC 5 is legacy System.Web on Windows/IIS.

❌ MYTH: You can skip server-side validation if client validation exists.
✅ TRUTH: Never trust the browser — always validate on the server; client validation is UX only.

Project structure

ShopNest.Mvc/
├── Controllers/       ← HTTP request handlers
├── Models/            ← Domain entities + ViewModels
├── Views/             ← Razor .cshtml templates
├── Services/          ← Business logic (DI)
├── Data/              ← DbContext, migrations
├── Areas/Admin/       ← Admin module (Article 9+)
├── wwwroot/           ← CSS, JS, Bootstrap
└── Program.cs         ← DI + middleware pipeline

Hands-on — ShopNest Enterprise MVC (Product Catalog)

Step 1 — The wrong way

// ❌ BAD — fat controller, no ViewModel, sync DB call
public IActionResult Index()
{
    var products = _context.Products.ToList(); // blocks thread
    ViewBag.Message = "Welcome"; // magic strings
    return View(products); // exposes domain entity
}

Step 2 — The right way

// ✅ CORRECT — Routing on ShopNest (Product Catalog)
public async Task Index(CancellationToken ct)
{
    var model = await _productService.GetListingAsync(ct);
    return View(model); // strongly typed ViewModel
}

Step 3 — Apply Routing

app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
[Route("admin/[controller]")] public class AdminProductsController : Controller { }
dotnet build
dotnet run --project ShopNest.Mvc
# Verify in browser at https://localhost:5xxx

Common errors & fixes

🔴 Mistake 1: Fat controllers with EF Core queries inline
Fix: Move data access to services/repositories; keep controllers thin.

🔴 Mistake 2: Missing [ValidateAntiForgeryToken] on POST forms
Fix: Add anti-forgery token to prevent CSRF attacks on checkout and admin forms.

🔴 Mistake 3: Returning domain entities directly to Razor views
Fix: Use ViewModels — prevents over-posting and hides internal fields.

🔴 Mistake 4: Hard-coding connection strings in controllers
Fix: Use appsettings.json + User Secrets locally; Azure Key Vault in production.

Best practices

  • 🟢 Use async/await end-to-end for database and I/O calls
  • 🟢 Register DbContext as Scoped; avoid capturing it in singletons
  • 🟡 Use ViewModels — never pass EF entities directly to views
  • 🟡 Add [ValidateAntiForgeryToken] on every POST action
  • 🔴 Log structured data with Serilog — include OrderId, UserId, not passwords
  • 🔴 Use HTTPS, secure cookies, and authorization policies in production

Interview questions

Fresher level

Q1: What is Routing in ASP.NET Core MVC?
A: Routing is a core MVC capability used in ShopNest Enterprise MVC for Product Catalog. Explain in one sentence, then describe controller/view/service placement.

Q2: How would you implement Routing on a TCS-style delivery project?
A: Thin controllers, ViewModels, async EF Core, DI in Program.cs, Bootstrap 5 admin UI, and unit tests for services.

Q3: MVC vs Web API — when to use which?
A: MVC for server-rendered HTML (admin panels, SEO storefronts); Web API for JSON consumed by Angular/React/mobile.

Mid / senior level

Q4: Explain the MVC request lifecycle briefly.
A: Browser → Kestrel → Middleware → Routing → Controller action → Service/EF Core → Razor view → HTML response.

Q5: Common production mistake with this topic?
A: Skipping validation, exposing secrets in Git, or untested edge cases (null model, unauthorized user).

Q6: .NET 8/9 vs .NET Framework for MVC?
A: Core is cross-platform, faster, cloud-ready; Framework is maintenance mode on Windows/IIS.

Coding round

Write a LINQ query: top 3 customers by total order value on ShopNest orders.

var top = await _context.Orders
    .GroupBy(o => o.CustomerId)
    .Select(g => new { CustomerId = g.Key, Total = g.Sum(o => o.GrandTotal) })
    .OrderByDescending(x => x.Total).Take(3).ToListAsync();

Summary & next steps

  • Article 8: Routing in ASP.NET Core MVC — Conventional and Attribute
  • Module: Module 1: MVC Fundamentals · Level: BEGINNER
  • Applied to ShopNest Enterprise MVC — Product Catalog

Previous: IActionResult and Action Results in ASP.NET Core MVC
Next: Areas in ASP.NET Core MVC — Modular Applications

Practice: Add one small feature using today's pattern — commit with feat(mvc): article-08.

FAQ

Q1: What is Routing?

Routing helps ShopNest Enterprise MVC build maintainable Product Catalog features using ASP.NET Core MVC 8/9 best practices.

Q2: Do I need Visual Studio?

No — .NET 8 SDK with VS Code + C# Dev Kit works. Visual Studio 2022 Community is recommended for MVC scaffolding.

Q3: Is this asked in Indian IT interviews?

Yes — MVC topics from Modules 1–6 appear in TCS, Infosys, Wipro campus drives; architecture modules in lateral hires.

Q4: Which .NET version?

Examples target .NET 8 LTS and .NET 9 with C# 12+ syntax.

Q5: How does this fit ShopNest Enterprise MVC?

Article 8 adds routing to Product Catalog. By Article 100 you have a portfolio-ready enterprise MVC app.

Test your knowledge

Quizzes linked to this course—pass to earn certificates.

Browse all quizzes
ASP.NET Core MVC Tutorial

On this page

Introduction After this article you will Prerequisites Concept deep-dive Level 1 — Analogy Level 2 — Technical Level 3 — Architecture Project structure Hands-on — ShopNest Enterprise MVC (Product Catalog) Step 1 — The wrong way Step 2 — The right way Step 3 — Apply Routing Common errors & fixes Best practices Interview questions Fresher level Mid / senior level Coding round Summary & next steps FAQ Q1: What is Routing? Q2: Do I need Visual Studio? Q3: Is this asked in Indian IT interviews? Q4: Which .NET version? Q5: How does this fit ShopNest Enterprise MVC?
Module 1: MVC Fundamentals
What is ASP.NET Core MVC — Complete Guide MVC Architecture in ASP.NET Core — Complete Guide ASP.NET Core MVC Request Lifecycle — End to End ASP.NET Core MVC Folder Structure Explained Controllers in ASP.NET Core MVC — Complete Guide Actions in ASP.NET Core MVC — Complete Guide IActionResult and Action Results in ASP.NET Core MVC Routing in ASP.NET Core MVC — Conventional and Attribute Areas in ASP.NET Core MVC — Modular Applications Middleware Pipeline in ASP.NET Core MVC
Module 2: Razor View Engine
Razor Syntax in ASP.NET Core MVC — Complete Guide Razor Expressions in ASP.NET Core MVC Layouts in ASP.NET Core MVC — _Layout and Master Pages Partial Views in ASP.NET Core MVC View Components in ASP.NET Core MVC Sections in Razor Layouts — @RenderSection ViewBag in ASP.NET Core MVC ViewData in ASP.NET Core MVC TempData in ASP.NET Core MVC Strongly Typed Views in ASP.NET Core MVC
Module 3: Models & Validation
Models in ASP.NET Core MVC — Complete Guide ViewModels in ASP.NET Core MVC — Best Practices DTOs in ASP.NET Core MVC Applications Model Binding in ASP.NET Core MVC — Complete Guide Validation in ASP.NET Core MVC Data Annotations for Model Validation in MVC FluentValidation in ASP.NET Core MVC Custom Validation Attributes in ASP.NET Core MVC Client-Side Validation with jQuery Unobtrusive Server-Side Validation in ASP.NET Core MVC
Module 4: CRUD Operations
Create Operations in ASP.NET Core MVC CRUD Read Operations in ASP.NET Core MVC CRUD Update Operations in ASP.NET Core MVC CRUD Delete Operations in ASP.NET Core MVC CRUD Pagination in ASP.NET Core MVC Sorting in ASP.NET Core MVC — Complete Guide Filtering in ASP.NET Core MVC Search Functionality in ASP.NET Core MVC File Upload in ASP.NET Core MVC Export Features in ASP.NET Core MVC — Excel and PDF
Module 5: Entity Framework Core
Entity Framework Core Setup in ASP.NET Core MVC DbContext in ASP.NET Core MVC — Complete Guide Code First with EF Core in MVC Applications EF Core Migrations in ASP.NET Core MVC CRUD with EF Core in ASP.NET Core MVC EF Core Relationships in ASP.NET Core MVC LINQ Queries with EF Core in MVC Repository Pattern in ASP.NET Core MVC Unit of Work Pattern in ASP.NET Core MVC EF Core Performance Optimization in MVC
Module 6: Authentication & Authorization
ASP.NET Core Identity in MVC Applications Login System in ASP.NET Core MVC User Registration in ASP.NET Core MVC Roles and Role-Based Authorization in MVC Claims-Based Authorization in ASP.NET Core MVC Authorization Policies in ASP.NET Core MVC JWT Authentication with ASP.NET Core MVC External Login — Google, Facebook, Microsoft Forgot Password and Email Confirmation in MVC Security Best Practices in ASP.NET Core MVC
Module 7: Advanced MVC
Filters in ASP.NET Core MVC — Action, Exception, Authorization Custom Middleware in ASP.NET Core MVC Session State in ASP.NET Core MVC Caching in ASP.NET Core MVC — In-Memory and Distributed Dependency Injection in ASP.NET Core MVC Logging with Serilog in ASP.NET Core MVC Exception Handling in ASP.NET Core MVC Localization and Globalization in ASP.NET Core MVC Custom Tag Helpers in ASP.NET Core MVC Background Services in ASP.NET Core MVC
Module 8: Enterprise Architecture
Clean Architecture with ASP.NET Core MVC CQRS Pattern in ASP.NET Core MVC MediatR in ASP.NET Core MVC Applications Repository Layer Design in Clean Architecture MVC Service Layer Design in ASP.NET Core MVC Domain Layer in ASP.NET Core MVC Infrastructure Layer in ASP.NET Core MVC SOLID Principles in ASP.NET Core MVC Design Patterns in ASP.NET Core MVC Microservices Migration from Monolithic MVC
Module 9: UI & Frontend
Bootstrap 5 in ASP.NET Core MVC — Complete UI Guide Admin Dashboard Design in ASP.NET Core MVC AJAX with ASP.NET Core MVC jQuery Integration in ASP.NET Core MVC Applications DataTables Integration in ASP.NET Core MVC Chart.js Dashboards in ASP.NET Core MVC SweetAlert Notifications in ASP.NET Core MVC Toast and Push Notifications in MVC Responsive UI Design in ASP.NET Core MVC Dark Mode in ASP.NET Core MVC Applications
Module 10: Real Projects
Build a Student Management System with ASP.NET Core MVC Build an HRMS with ASP.NET Core MVC Build an E-Commerce Store with ASP.NET Core MVC Build a Hospital Management System with MVC Build a CRM with ASP.NET Core MVC Build an ERP Module with ASP.NET Core MVC Build an Inventory Management System with MVC Build a Payroll System with ASP.NET Core MVC Build a Multi-Tenant SaaS with ASP.NET Core MVC ShopNest Enterprise MVC Application — Capstone Project