Controller in MVC
Controller in MVC
1) The controller handles user requests. so when a user hit any URL from browser controller
handle user requests.
2) Controller is a class and this controller class derived from the base class
3) In the controller class, it contains a method which is an action method. so every public
The action method in the controller class is accessible from a browser.
4) When we create a new controller it must use the Controller keyword at the end.
example if we create Home controller you need to give a name like
HomeController. so whatever name you can write but at the end must use
Controller keyword.
5) When we create multiple controllers with a different name so all multiple controllers
handle user requests.
2) Controller is a class and this controller class derived from the base class
3) In the controller class, it contains a method which is an action method. so every public
The action method in the controller class is accessible from a browser.
4) When we create a new controller it must use the Controller keyword at the end.
example if we create Home controller you need to give a name like
HomeController. so whatever name you can write but at the end must use
Controller keyword.
5) When we create multiple controllers with a different name so all multiple controllers
are store in the Controller folder in MVC.
when you request from browser controller responsibility is to handle user request and
return response to the user .
Let's understand how to create a controller .
when you request from browser controller responsibility is to handle user request and
return response to the user .
Let's understand how to create a controller .
Above you can see an image . if you want to add a new controller then right-click on controller
folder and add new Controller
Right-click on controller folder -> Add -> Controller.
After adding the controller, you can see different options above so you can select any one option to add a controller. click on MVC 5 Controller- Empty.
after selecting an empty controller from the above image, you can give any name for the controller .
but at the end Controller keyword is compulsory.
so if you want to add Home controller so you need to give name Home and after Home keyword Controller keyword is compulsory.
above image, all controllers reside in the Controllers folder. when you create an empty controller by default it creates an Index method. so when any user requests the Index method of Learn controller it will call the Index method to perform logic and give a response to the user. you can see below the image when we run the application and call index method it will show response in the browser.
Comments
Post a Comment