Posted By : Murugan Andezuthu Dharmaratnam
Posted On : 22 January 2015
Keywords : Controller,Controllers in MVC,Basics of MVC controller,What is Controller,Controller functions

Controllers In MVC

Introduction To Controllers

The controller, as the name implies, controls the application logic and acts as the coordinator between the view and the model.
Controllers receive input from users via the view, then work with the model to perform specific actions, passing the results back to the view.
Controllers process incoming requests, handle user input and interactions, and execute appropriate application logic. A controller class typically calls a separate view component to generate the HTML markup for the request.
All controller classes must be named by using the "Controller" suffix.

User requests an MVC application through the browser, controller is responsible for returing the response to that request. Controller undergoing one or more actions and returns action results to browser.
The actions may return files,views or may redirect to another controller actions.

Controller Basics

There will be a controller folder which contains controller classes.
These are responsible for processing incoming requests, handling input, saving data, and sending a response to send back to the client.
Home Controller.cs contains some actions include Index and About.
The example given below

Adding Controller To Application

To add a new controller to the application,

  • Right click on "Controller" folder under the application name in Solution Explorer
  • Select the option "ADD"
  • Select "Controller"
  • A dialogue box will be appearing for giving controller name.
  • Give the controller name and click "ADD"
  • The newly created controller will be present in the controller folder.
  • Controller Class

    The following is showing a sample controller class named as StudentController

    Controller Actions

    A controller exposes controller actions.
    An action is a method on a controller that gets called when you enter a particular URL in your browser address bar.
    The methods in controllerclasses referred to as controller actions that do all the heavy lifting that's involved in processing requests.

    Controller With Multiple Actions

    The following is showing a sample controller class named as StudentController with multiple actions.

    Murugan Andezuthu Dharmaratnam

    Murugan is a technology leader with 14 years of hands-on experience in full life cycle systems design, development, implementation, and management. In addition to systems design and development, his core competencies include cloud design and architecture, interactive web applications and websites development, mobile computing, and Healthcare Information Technology. His experience is very diverse with a broad range of technologies within multiple industry settings including private, public, and non-profit. Coupled with his technology expertise, Murugan is a well-organized, result-oriented, and a highly analytical leader with proven track record in developing and implementing very complex systems.