- Hands-On Full:Stack Web Development with ASP.NET Core
- Tamir Dresher Amir Zuker Shay Friedman
- 245字
- 2021-06-10 19:37:26
Creating a view
To create a view, we first need to create the matching folder if it doesn't already exist, and then create the file. Follow these steps to accomplish that:
- On Solution Explorer, right-click on the project name and choose Add | New Folder.
- Set the name as Views and click Enter.
- Right-click on the newly created Views directory and, again, choose Add | New Folder.
- Set the new folder name as Home and click Enter.
- Right-click on the new Home folder and choose Add | View....
On the Add View dialog, do the following:
- Set the View name as Index.
- Choose Empty (without model) on the Template field.
- Uncheck the Use a layout page checkbox.
- Click Add:

- The new view has now been scaffolded for you.
- Find the <body></body> tags and change them to <body>I'm a fullstack developer!</body>.
Now that we have the view ready, we need to instruct the controller action to show the view:
- Open the HomeController class, which is in the Controllers/HomeController.cs file.
- Find the following line:
return Content("Hello from MVC!");
Replace it with this line:
return View();
- Run the application (press F5, or go to Debug | Start Debugging).
- The browser should open and look similar to the following screenshot:

- Congratulations! You have a working ASP.NET Core MVC view!
For now, this fits all of our SPA needs. We will dive into the HTML and view aspects more deeply when we discuss Angular in the next part of this book.
推薦閱讀
- Cisco OSPF命令與配置手冊
- Modern JavaScript Web Development Cookbook
- 自動駕駛網絡:自智時代的網絡架構
- 新一代物聯網架構技術:分層算力網絡
- Web Application Development with R Using Shiny
- 局域網組建、管理與維護項目教程(Windows Server 2003)
- HTML5 Game development with ImpactJS
- Yii Application Development Cookbook(Second Edition)
- 新手易學:新手學淘寶開店
- Echo Quick Start Guide
- 網管第一課:網絡操作系統與配置管理
- 視聽變革:廣電的新媒體戰略
- SNS網站構建
- Alfresco Share
- 一板成功:高速電路研發與設計典型故障案例解析