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
Which attribute binds an action parameter from the URL route data?
Answer: [FromRoute]
[FromRoute] explicitly binds the parameter value from route template tokens rather than other sources.
What does app.MapControllers() do in the minimal hosting model?
Answer: Maps attribute-routed controller endpoints to the routing system
MapControllers() registers attribute-routed controllers as endpoints without requiring conventional routes.
How do you make a route parameter optional in ASP.NET Core attribute routing?
Answer: Add a ? after the parameter name: {id?}
Appending ? to a route token like {id?} marks it optional, allowing the route to match URLs with or without the segment.
Which helper method creates a 201 Created response with a Location header in an API controller?
Answer: CreatedAtAction()
CreatedAtAction() generates the Location header by routing to the specified action, following REST conventions for POST.
What does [Bind] attribute do on a model class in ASP.NET Core MVC?
Answer: Restricts which properties are included during model binding
[Bind("Prop1,Prop2")] whitelists only the specified properties, preventing over-posting security vulnerabilities.
Which route constraint restricts a route parameter to integer values only?
Answer: {id:int}
The :int route constraint ensures the segment matches only integer values, rejecting non-numeric requests at routing time.