AddMVC() vs AddControllersWithViews() vs AddControllers() vs AddRazorPages() in Asp.Net Core

Asp.net core has a couple of methods (AddControllers, AddMvc, AddRazorPages, AddControllersWithViews) to design your web application as per the need without adding unnecessary services.

Lets understand the difference among AddControllers, AddMvc, AddRazorPages & AddControllersWithViews methods.

Feature nameAddMVCAddControllers
WithViews
AddControllersAdd
RazorPages
ControllersYesYesYesYes
Model
Binding
YesYesYesYes
API
Explorer
YesYesYesNo
AuthorizationYesYesYesYes
CORSYesYesYesNo
ValidationsYesYesYesYes
Formatter
Mapping
YesYesYesNo
AntiforgeryYesYesNoYes
Temp DataYesYesNoYes
ViewsYesYesNoYes
PagesYesNoNoYes
Tag helpersYesYesNoYes
Memory
cache
YesYesNoYes
AddControllers vsAddMvc vs AddRazorPages vs AddControllersWithViews

Which method should we use in our application?

  • Web API – AddControllers()
  • Razor pages – AddRazorPage()
  • MVC – AddControllersWithViews()
  • Else – AddMVC()