Razor Pages & Views Flashcards
7 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 7 Razor Pages & Views flashcards as text
What attribute automatically binds a Razor Page's PageModel property to incoming HTTP POST form data?
Answer: [BindProperty]
[BindProperty] is the dedicated attribute for binding PageModel properties to form data on POST requests in Razor Pages.
Which handler method signature handles HTTP GET requests in a Razor Pages PageModel?
Answer: Both OnGet() and OnGetAsync() are valid
Both synchronous OnGet() and asynchronous OnGetAsync() are valid handler methods for GET requests in Razor Pages.
What Razor directive declares the model type for a Razor view, enabling IntelliSense and strong typing?
Answer: @model
The @model directive declares the C# type of the Model property available in the Razor view, enabling strong typing.
Where are Razor Pages .cshtml files stored by default in an ASP.NET Core project?
Answer: /Pages
By convention, Razor Pages files are stored in the /Pages folder, and the folder structure maps directly to URL routes.
What is the file extension for a Razor Page's code-behind PageModel file?
Answer: .cshtml.cs
The PageModel code-behind uses the .cshtml.cs extension, pairing it with the corresponding .cshtml view file.
Which method should a PageModel return to redirect the user to a different Razor Page after processing a POST?
Answer: return RedirectToPage()
RedirectToPage() is the Razor Pages method for redirecting to another page, resolving routes relative to the Pages folder.
What does the asp-page Tag Helper attribute do when applied to an anchor tag in a Razor view?
Answer: Generates an href URL pointing to the specified Razor Page
The asp-page tag helper generates the correct href URL for the specified Razor Page using ASP.NET Core's routing system.