Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Built-in base class for controllers in ASP.NET MVC: Controller or ControllerBase?

What is the built-in base class for controllers in ASP.NET MVC:

System.Web.Mvc.Controller or System.Web.Mvc.ControllerBase?

It is unclear to me after searching on Google:

  1. On www.ASP.NET: " A controller is a class that derives from the base System.Web.Mvc.Controller class."

  2. On codeproject: "The abstract ControllerBase class represents the base class for all MVC controllers."

  3. On MSDN: "The base class for all controllers is the ControllerBase class, which provides general MVC handling. The Controller class inherits from ControllerBase and is the default implement of a controller."

  4. In the book "Pro ASP.NET MVC 5 Framework" from Adam Freeman: "In ASP.NET MVC, controllers are just C# classes (usually inheriting from System.Web.Mvc.Controller, the framework's built-in controller base class)."

Who is right? What does "Built-in base class" mean exactly in this context? Is "Controller" the built-in base class and "ControllerBase" the ???? (what would be the right wording?) base class?

like image 791
Jonathan Orditz Avatar asked Oct 03 '15 19:10

Jonathan Orditz


People also ask

What is the base class of controller in MVC?

On MSDN: "The base class for all controllers is the ControllerBase class, which provides general MVC handling. The Controller class inherits from ControllerBase and is the default implement of a controller."

What is the difference between controller and ControllerBase?

Controller derives from ControllerBase and adds support for views, so it's for handling web pages, not web API requests. If the same controller must support views and web APIs, derive from Controller . The following table contains examples of methods in ControllerBase . Returns 400 status code.

What is the base class for store and controller?

The ControllerBase class is a base class for all controller classes. It provides general MVC handling.

Is it necessary for the MVC controller class to inherit from the base class controller?

Standard view-based MVC controllers should inherit from Controller . In both frameworks, controllers are used to organize sets of action methods.


1 Answers

By Defination

ControllerBase : A base class for an MVC controller without view support.

Controller : A base class for an MVC controller with view support.

Thus if we are not creating views i.e. creating Web API use ControllerBase else use Controller.

like image 104
Nidhi Khullar Avatar answered Sep 27 '22 16:09

Nidhi Khullar