21. Using Controllers with Views, pt. 1 Flashcards

1
Q

What is the Razor view engine responsible for?

A

generating HTML responses that can be displayed directly to the user (as opposed to the JSON and XML responses, which are typically consumed by other applications).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a view?

A

Views are files that contain C# expressions and HTML fragments that are processed by the view engine to generate HTML responses.
The View method creates an instance of the ViewResult class, which implements the IActonResult interface and tells the MVC Framework that a view should be used to produce the response for the client. The argument to the View method is called the view model and provides the view with the data it needs to generate a response.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are views?

A

Views are files that contain a mix of static HTML content and C# expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why are views useful?

A

Views are used to create HTML responses for HTTP requests. The C# expressions are evaluated and combined with the HTML content to create a response.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How are views used?

A

The View method defined by the Controller class creates an action response that uses a view.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Are there any pitfalls or limitations to views?

A

It can take a little time to get used to the syntax of view files and the way they combine code and content.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Are there any alternatives to views?

A

There are a number of third-party view engines that can be used in ASP.NET Core MVC, but their use is limited.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why do some files in the Views folder start with underscore?

A

Files in the Views folder whose names begin with an underscore (the _ character) are not returned to the user, which allows the file name to differentiate between views that you want to render and the files that support them. View imports files and layouts (which I describe shortly) are prefixed with an underscore.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are directives?

A

Directives are expressions that give instructions to the Razor view engine. The @model expression is a directive, for example, that tells the view engine to use a specific type for the view model, while the @using directive tells the view engine to import a namespace.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is content expression? And give examples of content expressions.

A

Razor content expressions produce content that is included in the output generated by a view.

@
This is the basic Razor expression, which is evaluated, and the result it produces is inserted into the response.

@if
This expression is used to select regions of content based on the result of an expression. See the “Using Conditional Expressions” section for examples.

@switch
This expression is used to select regions of content based on the result of an expression. See the “Using Conditional Expressions” section for examples.

@foreach
This expression generates the same region of content for each element in a sequence. See the “Enumerating Sequences” for examples.

@{ … }
This expression defines a code block. See the “Using Razor Code Blocks” section for an example.

@:
This expression denotes a section of content that is not enclosed in HTML elements. See the “Using Conditional Expressions” section for an example.

@try
This expression is used to catch exceptions.

@await
This expression is used to perform an asynchronous operation, the result of which is inserted into the response. See Chapter 24 for examples.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly