In this article, I am going to discuss the ideas about Controller in MVC with examples. Please read our previous articles before moving on to this article where we discussed the MVC application ASP.NET Model and View. As part of this article, we are going to discuss the following contents which are related to Controller in MVC.
Controller in MVC :
- In ASP.NET MVC, a Controller handles any incoming URL request and responsible for returning the response to that request.
- It is used to define and group a set of actions.
- allowing common sets of rules such as routing, caching, authorization etc to be applied on controller or action.
- Incoming requests are mapped to actions through routing.
- It inherit from Microsoft.AspNet.MVC.Controller namespace.
- Every controller class name must suffix with a word “Controller”.
- Controller is processed incoming request by the help of actions.
Add new Controller in MVC application :
Now we will discuss the below topics that is How can you create your own controller in the MVC application?
Step -1
First, you need to open a visual studio and create your own MVC project.
How can I create my first MVC application ?
Step -2
Now time to create your own controller so please follow the step.
Solution Explorer a Right-click on Controller Folder a Select MVC Controller Empty a Rename the controller name.
Please follow the below screens
![Controller in MVC](https://infosyntax.com/wp-content/uploads/2021/09/Add-Controller-in-MVC-application-1.png)
![](https://infosyntax.com/wp-content/uploads/2021/09/Add-Controller-in-MVC-application-2.png)
![](https://infosyntax.com/wp-content/uploads/2021/09/Add-Controller-in-MVC-application-3.png)
![](https://infosyntax.com/wp-content/uploads/2021/09/Add-Controller-in-MVC-application-4.png)
Step -3
Your controller was successfully created on step – 2. Define your own action logic in controller.
Please follow the below screens.
![](https://infosyntax.com/wp-content/uploads/2021/09/Add-Controller-in-MVC-application-5-1024x263.png)
Step – 4
This is our last/final step. Now you need to run the application then only you can able to see the appropriate results.
![](https://infosyntax.com/wp-content/uploads/2021/09/Add-Controller-in-MVC-application-6.png)
Warm up
- A Controller handles any incoming URL request and is responsible for returning the response to that request.
- Allowing common sets of rules such as routing, caching, authorization, etc to be applied on controller or action.
- Incoming requests are mapped to actions through routing.
- It inherits from Microsoft.AspNet.MVC.Controller namespace.