官术网_书友最值得收藏!

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:

  1. On Solution Explorer, right-click on the project name and choose Add | New Folder.
  2. Set the name as Views and click Enter.
  3. Right-click on the newly created Views directory and, again, choose Add | New Folder.
  4. Set the new folder name as Home and click Enter.
  5. Right-click on the new Home folder and choose Add | View....

On the Add View dialog, do the following:

  1. Set the View name as Index.
  2. Choose Empty (without model) on the Template field.
  3. Uncheck the Use a layout page checkbox.
  1. Click Add:
  1. The new view has now been scaffolded for you.
  2. 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:

  1. Open the HomeController class, which is in the Controllers/HomeController.cs file.
  2. Find the following line:
return Content("Hello from MVC!");

Replace it with this line:

return View();
  1. Run the application (press F5, or go to Debug | Start Debugging).
  2. The browser should open and look similar to the following screenshot:
  1. 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.

主站蜘蛛池模板: 北宁市| 鄯善县| 平罗县| 天镇县| 白城市| 唐山市| 吐鲁番市| 牙克石市| 东辽县| 东乡族自治县| 萨嘎县| 大邑县| 定陶县| 拜泉县| 宝兴县| 东山县| 荃湾区| 内黄县| 普定县| 岳西县| 红原县| 天祝| 会泽县| 巴南区| 宁安市| 宣威市| 大城县| 神农架林区| 九台市| 长丰县| 利辛县| 临桂县| 高雄县| 昌黎县| 青海省| 延边| 孟村| 苏尼特右旗| 博湖县| 咸阳市| 任丘市|