ADDController.md - brainchildservices/curriculum GitHub Wiki

SLIDE-1

  • ASP.NET MVC Controller:

Controller interacts among Models and Views.

SLIDE-2

SLIDE-3

  • Now let's add a controller to your project.

image

SLIDE-3(DOWNWARDS)

  • Use the following procedure to add a Controller to your project:

image

SLIDE-4

How to create new Controller Using VS Code.

Go to the Explorer window in VS Code. Right Click the Controllers folder and point to New File, followed by clicking the New File.

image

SLIDE-4(DOWNWARDS)

Now, you can type in controller name as HelloWorldController.cs and press the Enter button.

image

SLIDE-4(DOWNWARDS)

Copy and paste the below code into HelloWorldController.cs

 using Microsoft.AspNetCore.Mvc;  

 namespace SampleMVCApps.Controllers  
 {  
     public class HelloWorldController:Controller  
     {  
         public IActionResult Index()  
         {     
             ViewData["Message"]="Hello, This is my view";  
             return View();  
         }  

         public IActionResult Welcome()  
         {  
             ViewData["Message"]="Hello, Welcome to HelloWorld Application";  
             return View();  
         }  
     }  
 }  

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