All subjects.NET · 55 questions · 17 junior / 30 mid / 8 senior

ASP.NET MVC quiz and interview questions

ASP.NET MVC is still everywhere in company code, and its ideas live on in ASP.NET Core. Interviews ask how a request is routed to a controller, how data reaches the view, how validation works and how to keep forms secure. Practise them here.

ASP.NET MVC quiz55 questions in the bank · 10 per round
Level
Question type
Mode

ASP.NET MVC: key concepts

Model, View, Controller
The controller handles the request and talks to the model (data and rules); the view renders HTML. Keeping them separate makes code easier to test and change.
Routing
Routes map URLs to controller actions, e.g. {controller=Home}/{action=Index}/{id?}. Attribute routing puts the route right on the action.
Razor views
.cshtml files mixing HTML with C# via @. Layouts hold the shared page shell; partial views are reusable pieces.
Model binding and validation
Form, route and query values are bound to action parameters. Data annotations like [Required] feed ModelState.IsValid.
ViewData, ViewBag, TempData
ViewData and ViewBag pass data to the current view. TempData survives one redirect — handy for success messages.
Filters
Authorization, action, result and exception filters run code around actions — e.g. [Authorize], logging or error handling.

All 55 ASP.NET MVC questions with answers

Try each one first, then open the answer. Making a class test? Use the test maker.

  1. juniorConcepts

    In MVC, which part handles the incoming request and chooses what to return?

    • A. Model
    • B. View
    • C. Controller
    • D. Router
    Show answer

    C. Controller — The controller's action receives the request, works with the model and returns a result such as a view or a redirect.

  2. juniorConcepts

    What does the View do in MVC?

    • A. Stores data
    • B. Renders the user interface (HTML)
    • C. Handles routing
    • D. Talks to the database
    Show answer

    B. Renders the user interface (HTML) — Views should only display data passed to them. Business logic belongs in the model or services.

  3. juniorPredict the output

    With the default route below, which action handles GET /Products/Details/7?

    {controller=Home}/{action=Index}/{id?}
    • A. HomeController.Index()
    • B. ProductsController.Details(id: 7)
    • C. ProductsController.Index(7)
    • D. DetailsController.Products(7)
    Show answer

    B. ProductsController.Details(id: 7) — The first segment is the controller (Products), the second the action (Details), and 7 binds to the optional id.

  4. midConcepts

    Which one survives a redirect?

    • A. ViewData
    • B. ViewBag
    • C. TempData
    • D. Local variables
    Show answer

    C. TempData — TempData is kept until it's read on the next request, so it works for "Saved!" messages after RedirectToAction.

  5. juniorConcepts

    What is Razor?

    • A. A JavaScript framework
    • B. The view syntax that mixes HTML and C# using @
    • C. A database
    • D. A test runner
    Show answer

    B. The view syntax that mixes HTML and C# using @ — In a .cshtml file, @Model.Name or @foreach (...) runs C# while the rest is plain HTML.

  6. juniorPredict the output

    What HTML does this Razor render?

    @{ var n = 3; }
    <p>@(n * 2)</p>
    • A. <p>n * 2</p>
    • B. <p>6</p>
    • C. <p>@(n * 2)</p>
    • D. <p>3</p>
    Show answer

    B. <p>6</p> — @( ... ) evaluates the C# expression and writes the result: 6.

  7. midConcepts

    What is a partial view for?

    • A. Hiding parts of a page
    • B. A reusable piece of markup used inside other views
    • C. Loading pages faster
    • D. Partial page caching only
    Show answer

    B. A reusable piece of markup used inside other views — E.g. _ProductCard.cshtml rendered in several pages with <partial name="_ProductCard" model="p" />.

  8. midConcepts

    What does a layout page do?

    • A. Defines routes
    • B. Provides the shared page shell (header, footer) with @RenderBody() for each view
    • C. Validates forms
    • D. Stores CSS only
    Show answer

    B. Provides the shared page shell (header, footer) with @RenderBody() for each view — _Layout.cshtml avoids repeating the same header and footer in every view.

  9. midConcepts

    What is model binding?

    • A. Linking two models
    • B. Automatically filling action parameters from form, route and query values
    • C. Binding CSS to models
    • D. Mapping models to tables
    Show answer

    B. Automatically filling action parameters from form, route and query values — public IActionResult Save(Product p) gets p.Name, p.Price… from the posted form fields with matching names.

  10. juniorFind the bug

    What's missing from this action?

    [HttpPost]
    public IActionResult Save(Product p)
    {
        _db.Products.Add(p);
        _db.SaveChanges();
        return RedirectToAction("Index");
    }
    • A. Nothing
    • B. A ModelState.IsValid check — invalid data gets saved
    • C. It must return View()
    • D. Save must be async
    Show answer

    B. A ModelState.IsValid check — invalid data gets saved — Validation attributes only populate ModelState; you must check it: if (!ModelState.IsValid) return View(p);

More subjects

Need software for your business instead? I'm an AI automation & full-stack developer — see what I build.

Chat on WhatsApp