How to Create new controller in MVC C#

Updated on     Kisan Patel

In Previous Article I told you About how to create a new MVC Project in Visual studio. Here is the link

Now How to add new controller in MVC
so
after creating a new project or in your project goto your Solution Explorer then Goto Controller folder and right click on controller folder -> add -> controller.

Right click on controller folder -> add -> Controller

Right click on controller folder -> add -> Controller

Then Select Your controller type in Add scaffold then click on Add.
there are many type of controller which creates controller about their types
1) MVC Controller – Empty
2) MVC controller with read/Write Actions
3) MVC Controller with views, using Entity framework

1) MVC Controller – Empty
MVC Controller – Empty is a controller which creates just controller with one single view index. but it will not create any scaffold in view folder.

Add MVC Controller - Empty

Add MVC Controller – Empty

Add Name of your controller

Add Name of your controller and click Add

2) MVC controller with read/Write Actions
MVC controller with read/Write Actions will add the Create, Details, Edit, Delete and List view in controller with entity framework . but it will not create any scaffold in view folder.

3) MVC Controller with views, using Entity framework
MVC Controller with views, using Entity framework will create View pages with given model and context . it will create Create, Details, Edit, Delete and List page with scaffold in view folder

Add Controller with entity framework

Add Controller with entity framework and click Add

Give Your name to your controller then select model and context

Give Your name to your controller then select model and context and click Add


ASP.NET MVC

Leave a Reply