ADDView.md - brainchildservices/curriculum GitHub Wiki

Slide 1

Add A View

Then following is the folder and file structure of the Views

image

Slide 2

Right-click on the Views folder and then select Add => View option which will open the Add View window as shown in the below image. Here, you need to select the Razor View item and then click on the Add button.

image

Slide 3

Once you click on the Add button, then it will open the Add Razor View window. Here, you need to give the View name as Index, Select the Empty (without model) template, uncheck the create a partial view and use a layout page checkbox and then click on the Add button as shown in the below image.

image

Slide 4

Once you click on the Add button then it should create the Index.cshtml view within the Home folder as shown in the below image.

image

Slide 5

Now open Index.cshtml file and then copy and paste the following code in it.

 @{
     Layout = null;
 }
 <!DOCTYPE html>
 <html>
 <head>
     <meta name="viewport" content="width=device-width" />
     <title>Index</title>
 </head>
 <body>
     <h1>Index view belongs to Views/Home folder</h1>
 </body>
 </html>

Slide 6

With the above changes in place, now run the application and you should get the output as expected as shown in the below image.

image

Ref:- https://dotnettutorials.net/lesson/views-asp-net-core-mvc/

Slide 7

Creating a View in VS Code

Go to the Explorer window in VS Code. Right Click the Views folder and point to New Folder, followed by clicking the New Folder. Then, add the new folder named HelloWorld.

image

Slide 8

Right-click the HelloWorld folder and point to New File, followed by clicking the New File.

image

Slide 9

Now, you can type in View name as Index.cshtml and press the Enter button.

image

Slide 10

Copy and paste the below code into Views/HelloWorld/Index.cshtml.

 @{  
     ViewData["Title"]="Index";  
 }  

 <h2>Index</h2>  
 <hr>  

 <p>@ViewData["Welcome"]</p>  

Similarly, you can create a welcome view. Copy and paste the below code into Views/HelloWorld/Welcome.cshtml.

 @{  
     ViewData["Title"]="Welcome";  
 }  

 <h2>Welcome</h2>  
 <hr>  

 <p>@ViewData["HelloWorld"]</p> 

Ref:- https://www.c-sharpcorner.com/article/getting-started-with-asp-net-core-mvc-apps-using-vs-code/

⚠️ **GitHub.com Fallback** ⚠️