- 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.
推薦閱讀
- 廣電5G從入門(mén)到精通
- 6G潛在關(guān)鍵技術(shù)(下冊(cè))
- Mastering Machine Learning for Penetration Testing
- Spring Cloud微服務(wù)架構(gòu)進(jìn)階
- 物聯(lián)網(wǎng)時(shí)代
- Wireshark網(wǎng)絡(luò)分析就這么簡(jiǎn)單
- Learning Swift(Second Edition)
- CCNP TSHOOT(642-832)認(rèn)證考試指南
- 面向5G-Advanced的關(guān)鍵技術(shù)
- 物聯(lián)網(wǎng)工程導(dǎo)論(第3版)
- 移動(dòng)物聯(lián)網(wǎng):商業(yè)模式+案例分析+應(yīng)用實(shí)戰(zhàn)
- Web用戶(hù)查詢(xún)?nèi)罩就诰蚺c應(yīng)用
- 信息技術(shù)安全評(píng)估準(zhǔn)則:源流、方法與實(shí)踐
- 區(qū)塊鏈技術(shù)與應(yīng)用:打造分布式商業(yè)新生態(tài)
- Microservices Development Cookbook