Reputation: 1131
I'm trying to find out why in all docs I see services.AddMvc
or services.AddMvcCore
in Startup.cs
but in ASP.NET Core MVC 3.1 template that's created by VS I do not have AddMvc but mvc still works....
the only thing I have related t MVC is
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
can anyone explain why?
Upvotes: 10
Views: 14598
Reputation: 1182
I think all the docs you are seeing is for .net core 2.*.
For More Information -> https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-2.2&tabs=visual-studio
Upvotes: 0
Reputation: 20116
As the doc has said that asp.net core 3.0+ template use these new
methodsAddControllersWithViews
,AddRazorPages
,AddControllers
instead of AddMvc
.
However, AddMvc
continues to behave as it has in previous releases.AddMvc()
is really just a wrapper around a bunch of other methods that register services. See Source:
You could either use AddMvc
to register for MVC, Razor Pages,API or use individual AddControllersWithViews
(for MVC only) and AddRazorPages
(for Razor Pages only).
Upvotes: 12