How to Add Controller in MVC

There are two approaches to add the controller in the ASP.NET MVC.

Approach-1: Using Scaffolding method.

  • Right Click on Controller Folder
  • Select Add -> Controller 
  • Following picture shows the controller template selected.


  • Click Add button
  • Name the controller as given image
  • Click on the Add button and that all the controller will generate in the Controller Folder as given bellowed Image
Approach - 2: By adding a normal class
  • Right Click on Controller folder 
  • Select Add Class or New Item
  • Import the namespace using System.Web.Mvc;
  • Inherit the class name Controller in it.
  • And thats all the controller is ready.



Comments

Popular posts from this blog

Code First Approach with Entity Framework

Getting Ready for Python Development on Ubuntu using VSCode

Designing Model class with validation in ASP.NET MVC