Hello friends, I hope you all are doing great. In today's tutorial, we are gonna Create a New Controller in ASP.NET MVC. It's 6th tutorial in our ASP.Net MVC series. We have already had a look at basic Introduction to Controllers in ASP.NET MVC and they are used to communicate between Views & Models.So, now we are gonna have a look at How to Create a New Controller in ASP.NET MVC. It's a very quick tutorial, as there's not much to do with Controller rite now, we will just create one. So, let's get started with it:
Create a New Controller in ASP.NET MVC
- In order to Create a New Controller in ASP.NET MVC, you have to right click on the Controllers folder in Solution Explorer.
- Now click on the Add and then click on Controllers as shown in below figure:
- It will open up a new window which will have different types of Controllers and are used for different purposes.
- Here, we have to select the second one as we want to perform read/ write actions.
- So, select MVC 5 Controller with read / write actions and then clock Add Button, as shown in below figure:
- When you click the Add Button, it will ask for the Controller name.
- I have assigned it a name StudentController, now click the Add button, as shown in below figure:
- Now when we click the Add button, then a scaffolding operation will start by visual studio and it will automatically create our new controller.
- This new Controller file will also open up in our work space and it will have some classes by default in it, as shown in below figure:
- We have successfully created our new Controller to read or write data.
- In our previous lecture, we have already created a new Model in ASP.NET MVC.
- So, now we are only left with the Views which we are gonna create in our next tutorial and will also bind them together.
- Here's a video demonstration of How to Create a new Controller in ASP.NET MVC, it will help for better understanding: