โ† All ASP.NET Core Flashcard Decks

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
  1. Which Tag Helper renders a client-side validation error message for a specific model property?

    Answer:

    The asp-validation-for tag helper on a span element renders validation error messages for the specified model property.

  2. What is a Partial View in ASP.NET Core Razor?

    Answer: A reusable .cshtml file containing HTML markup that can be rendered inside other views

    A Partial View is a reusable .cshtml file rendered within another view using @Html.PartialAsync() or the tag helper.

  3. How does a View Component differ from a Partial View in ASP.NET Core?

    Answer: View Components have their own C# class with business logic, while Partial Views are purely HTML templates

    View Components include a C# class with an InvokeAsync method for business logic and data retrieval, making them more powerful than simple Partial Views.

  4. Which syntaxes are valid for invoking a View Component from a Razor view?

    Answer: Both @await Component.InvokeAsync() and the tag helper syntax

    View Components support both the @await Component.InvokeAsync('Name') method call and the tag helper syntax.

  5. What does the default anti-forgery token behavior on a Razor Pages POST form protect against?

    Answer: Cross-Site Request Forgery (CSRF) attacks

    ASP.NET Core automatically generates and validates anti-forgery tokens on Razor Pages POST forms to prevent CSRF attacks from malicious sites.

  6. When Razor renders @value in a view, how does it handle the output to protect against XSS?

    Answer: It HTML-encodes the output, escaping characters like , and &

    The @value Razor syntax automatically HTML-encodes output, converting characters like < to < to prevent XSS injection.

  7. What is the lifetime of data stored using the [TempData] attribute in a Razor Pages PageModel?

    Answer: Available until read, typically surviving one redirect in a Post-Redirect-Get pattern

    TempData persists only until the data is read (typically on the next request), making it ideal for passing messages across a Post-Redirect-Get redirect.