DotNet

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What does the Razor .cshtml file consist?

@page @model [projectName].Ui.Pages.[pageName] @{ [C# code] } [html code]

What is Dependency Injection?

A dependency is any object that another object requires. If class A needs a method that is registered with class B, then the definition of class A will inevitably call class B directly. In case we need to change the implementation of class B, we will have to modify class A as well. The Inversion of Control principle suggests we should create an interface and call A with the interface, then B can be modified without having to affect A. Dependency injection is an implementation of this idea. Instead of calling multiple classes directly in a page model, the page model constructor should take a service object, and register the methods into the service class so that the service class can have access to the methods. The DotNet framework handles the lifecycle (creation and disposal) of the dependency instances automatically for us.

What is a model?

A model can be thought as the data schema of the data structure that you need on the back end, as well as Data Transfer Object (DTO), that defines the data that will be sent over the network, in this case to the web API. It is a class that allows annotations on its properties.

What is a service?

A service is a class that achieve the Dependency Injection in a DotNet app. The methods that are needed in the new class are registered to the service class, then the service object is passed to the constructor of the pagemodel.

What is an Anchor page helper?

An Anchor page helper enhances the html tag <a></a> by allowing asp attributes such as asp-page: set the href attribute of the html tag asp-page-handler: route to specific page handlers

What are client content and server code in Razor Pages?

Client content: Contains what you're used to in webpages: HTML markup (elements), style information such as CSS, maybe some client script such as JavaScript, and plain text Server code: Razor syntax lets you add server code to your client content. If there is server code in the page, the server runs that code first, before it sends the page to the browser. From the browser's perspective, client content that's generated by your server code is no different than any other client content

What does the Pages folder in Razor Pages consist?

Each Razor page is a pair of files: * A .cshtml file that contains markup with C# code using Razor syntax. * A .cshtml.cs PageModel class file that defines: ** Page handlers for requests sent to the page. ** Data used to render the page. This separation of the markup file and the PageModel class file allows separation of logic from presentation.

How to build an application after applying all the changes?

Go to the project root directory, which is like [projectName].Ui in the case of Razor Pages, then run the terminal command dotnet build

How does @ work in Razor Pages?

If @ is followed by a Razor reserved keyword such as page or model, then it transitions into Razor-specific markup; otherwise, it transitions to C# The C# code after @ cannot have C# generics such as <> templates

How to run your webapp on Azure?

In Azure CLI: az webapp up

What does the program.cs file do?

It is the main entry point of the dotnet application. The dotnet application calls the Main method in the class defined in program.cs. For a webapp, the main method calls its method BuildWebHost, which first create a default builder, then call the UseStartup method to register the startup services to the host.

What does the Models folder in Razor Pages consist?

Model objects. A model object defines data properties and encapsulates logic or operations related to those data properties

What does the Razor PageModel .cshtml.cs class file consist?

Page handler methods. A handler method is the method that is executed as a result of a request. For example, an OnGet method in the Razor pages's PageModel class would be automatically executed for an HTTP GET request, or an OnPost method to handle form submissions. If asynchronous actions happen when calling the handlers, usually the methods are appended with the suffix Async (optionally) and equipped with the async keyword. public async [returnType] OnPostAsync() { } Every PageModel file usually defines an extension of the PageModel base class. The PageModel base class is defined in RazorPage native namespace "Microsoft.AspNetCore.Mvc.RazorPages"

What is Razor Pages in ASP.NET Core application?

Razor Pages is a server-side, page-centric programming model for building webpage UI Razor Pages can be broadly described as an HTML file where you can work with markup as you are used to, but you also have the advantage of adding server-side C# code by using Razor syntax. Razor pages have the extension .cshtml

What is Razor?

Razor is a simple markup syntax for embedding server-based code into webpages. Razor is a combination of HTML and C# where the C# code defines the dynamic rendering logic for the page.

What are services in Razor Pages?

Services define service classes, typed HTTPClient service architecture. It is responsible for executing all HTTP requests to the web API so that code is maintained in one place. Furthermore it is registered at startup as a service so that it may be injected where needed.

What does the Startup.cs file do?

Startup file defines a class that must have two methods: ConfigureServices Configure ConfigureServices add services to the startup class Configure uses the services in the app E.g. the ConfigureServices method takes an argument of service of IServiceCollection interface type. It has methods such as "AddScoped"

What is the file that stores the settings and configuration?

Startup.cs

What are Razor Tag Helpers in ASP.NET?

Tag Helpers are components for automating HTML generation in ASP.NET Core web applications. Most built-in Tag Helpers extend standard HTML elements you're familiar with and provide additional server-side attributes for the element, making them more robust. Common Razor Tag Helpers include: Label Tag Input Tag Validation Message Tag

What does @model [modelName] mean in a Razor page file?

The @model directive is Razor syntax specifying the type of the model made available to the Razor page. The modelName is often a class extension of the base PageModel class defined in the companion PageModel file.

What does @page mean in a Razor page file?

The @page directive is what makes this a Razor page. It indicates this page can handle HTTP requests. The @page directive must be the first directive on a Razor page.

What is an Input Tag Helper?

The syntax is exactly the same as the html input tag <input></input> except that it can have an attribute "asp-for" The input tag helper does: 1. automatically converts the layout into an appropriate type based on the data type of the value of "asp-for". If it is a boolean, then automatically layout a checkbox. If it is a string, then automatically layout a input box 2. automatically assigns an html id and name

What is a Label Tag helper?

The syntax is exactly the same as the html label tag: <label></label> except that it can have an attribute "asp-for" The value of asp-for="[value]" is automatically scoped to the PageModel file associated to the page file, so you don't need to use the @ syntax inside the value of the asp-for attribute.

How to inject service classes into the page that do CRUD (create, read, update, delete) operations?

The typical way is to use service class as a constructor parameter of the page model class

What is a Validation Message Tag helper?

Usually use the html span tag because it displays the validation message: <span></span> except that it can have an attribute "asp-validation-for" Does client side JQuery validation based on the data annotation attributes defined in the PageModel page or Model data property annotations, also prompts Razor engine to do server side validation

What annotations are allowed on model properties?

[Required] [Range(minimum: ..., maximum:...)] They are put above the property declaration. For a complete list of available annotations, see System.ComponentModel.DataAnnotations.

What is the file that lists out what libraries are referenced?

[projectName].csproj

What is the terminal command to create a RazorPages template?

dotnet new razor

What is the command to run your app?

dotnet run

What is the template to create a dotnet webapp?

in the correct directory, run terminal command: dotnet new [templateName] -o [yourProjectName] --[flag]

What are some template names?

webApp the template of a web app


Set pelajaran terkait

Metamorphic Processes and products

View Set

Chapter 4: Formation of the Solar System (Textbook Notes)

View Set

Marketing Chapter 17 Test- 12/11/15

View Set

N 204 ch 12 Collaborative practice and care coordination accross settings (final)

View Set

prep u 140 infection and inflammation

View Set

Chemical Reactions and Reaction Stoichiometry

View Set

Chapter 6: Appendicular Skeletal System

View Set

Benjamin Franklin "Poor Richard's Almanac"

View Set