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:
On www.ASP.NET: " A controller is a class that derives from the base System.Web.Mvc.Controller class."
On codeproject: "The abstract ControllerBase class represents the base class for all MVC controllers."
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."
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?
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."
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.
The ControllerBase class is a base class for all controller classes. It provides general MVC handling.
Standard view-based MVC controllers should inherit from Controller . In both frameworks, controllers are used to organize sets of action methods.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With