[Asp. Net Core] 2. Add controllers and views, asp. netcore
Controller
Before adding a Controller, let's take a look at some controllers that are automatically generated for us. Let's take a look at AccountController. cs
Let's take a look at the logon verification method Login.
What Should async do asynchronously? What is Task <IActionResult>? Var result = await _ signInManager. PasswordSignInAsync (model. Email, model. Password, model. RememberMe, lockoutOnFailure: false );?
Let's take a look at the following two articles:
Dudu:
Case study: Use async/await to implement parallelism in existing code
Jesse:
Async & await past and present (Updated)
Do you know what to do after reading these two articles? In particular, this figure clearly shows the running sequence of the image:
OK, the level is limited. I just read it and I know what it is. Why? As for the Principles and Applications, I will try it out... haha
Let's add a controller HelloWorldController.
View Views
We will add a view (no longer right-click to add the view as we did before. I personally think that it is better to create a controller to directly generate the corresponding Views folder. here we need to create it manually)
We create a new folder named HelloWorld under the Views folder, which has the same name as our controller.
Right-click the folder and we will find that there is a view for the options to be added.
This interface is the same as before, but we do not have a data model yet. We cannot create a model class or a data launch document class if we do not select it.
So, in another way, right-click the folder and choose "add"> "Create an item". On the MVC view page, our controller Action is "Index", so use the default Index. cshtml.
Modify the view page, remove the comment, and add the Title.
By default, the _ Layout page (_ ViewStart. cshtml), of course, as before, we can not use the default Layout page _ Layout, in Index. in cshtml, modify the Layout = "_ LayoutTest" to its own Layout page ";
The route is configured in the Satrtup. cs class.
Let's run it.
Transmit data
We receive two parameters: name and nums)
Pass ViewData to the view page
We receive the two parameters on the attempt page and output them:
Let's take a look at the output:
It seems that it is still very easy to get started. It is no big difference from before. It is estimated that it has not gone to the essence, and there is a more and more anxious look, but after all, there is too little information on the Internet, we still need to study and find that we will discuss the research together.
When we use Core for the first time, we basically organize online materials. I have not studied it before. I hope to study it with you. If there are any errors, I hope you can correct them; if you have any questions, I hope you can give me some advice.
Original article reprinted please respect labor results http://yuangang.cnblogs.com