โ† All ASP.NET Core Flashcard Decks

Routing & Controllers Flashcards

6 cards from real ASP.NET Core practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 Routing & Controllers flashcards as text
  1. Which attribute defines a route template directly on an ASP.NET Core controller action?

    Answer: [Route]

    [Route("path")] sets the route template for a controller or action, and can be combined with HTTP method attributes.

  2. What does the [ApiController] attribute do in ASP.NET Core?

    Answer: Enables automatic model validation, binding source inference, and problem details responses

    [ApiController] opts the controller into API-specific conventions like automatic 400 responses on validation failure.

  3. What route token represents an action name in a conventional route template?

    Answer: {action}

    {action} is the conventional route token that maps to the action method name in the default MVC route template.

  4. Which return type enables ASP.NET Core Web API actions to return multiple response types with proper metadata?

    Answer: IActionResult or ActionResult

    ActionResult allows returning both a typed result and different HTTP status code responses, enabling OpenAPI documentation.

  5. What is the purpose of [HttpGet("{id}")] on an action method?

    Answer: It constrains the action to GET requests and captures an 'id' route parameter

    Combining the HTTP method attribute with a template restricts the HTTP verb and defines the route in one declaration.

  6. What method is called to add MVC controllers with views in ASP.NET Core?

    Answer: services.AddControllersWithViews()

    AddControllersWithViews() registers controllers plus Razor view support, whereas AddControllers() registers controllers for APIs only.