Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
MvcServiceCollectionExtensions.AddControllersWithViews Method
Definition
- Namespace:
- Microsoft.Extensions.DependencyInjection
- Assembly:
- Microsoft.AspNetCore.Mvc.dll
- Package:
- Microsoft.AspNetCore.App.Ref v10.0.0
- Package:
- Microsoft.AspNetCore.App.Ref v11.0.0-preview.4.26230.115
- Package:
- Microsoft.AspNetCore.App.Ref v3.0.1
- Package:
- Microsoft.AspNetCore.App.Ref v3.1.10
- Package:
- Microsoft.AspNetCore.App.Ref v5.0.0
- Package:
- Microsoft.AspNetCore.App.Ref v6.0.36
- Package:
- Microsoft.AspNetCore.App.Ref v7.0.5
- Package:
- Microsoft.AspNetCore.App.Ref v8.0.19
- Package:
- Microsoft.AspNetCore.App.Ref v9.0.8
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
| AddControllersWithViews(IServiceCollection) |
Adds services for controllers to the specified IServiceCollection. This method will not register services used for pages. |
| AddControllersWithViews(IServiceCollection, Action<MvcOptions>) |
Adds services for controllers to the specified IServiceCollection. This method will not register services used for pages. |
AddControllersWithViews(IServiceCollection)
Adds services for controllers to the specified IServiceCollection. This method will not register services used for pages.
public static Microsoft.Extensions.DependencyInjection.IMvcBuilder AddControllersWithViews(this Microsoft.Extensions.DependencyInjection.IServiceCollection services);
static member AddControllersWithViews : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IMvcBuilder
<Extension()>
Public Function AddControllersWithViews (services As IServiceCollection) As IMvcBuilder
Parameters
- services
- IServiceCollection
The IServiceCollection to add services to.
Returns
An IMvcBuilder that can be used to further configure the MVC services.
Remarks
This method configures the MVC services for the commonly used features with controllers with views. This combines the effects of AddMvcCore(IServiceCollection), AddApiExplorer(IMvcCoreBuilder), AddAuthorization(IMvcCoreBuilder), AddCors(IMvcCoreBuilder), AddDataAnnotations(IMvcCoreBuilder), AddFormatterMappings(IMvcCoreBuilder), AddCacheTagHelper(IMvcCoreBuilder), AddViews(IMvcCoreBuilder), and AddRazorViewEngine(IMvcCoreBuilder).
To add services for pages call AddRazorPages(IServiceCollection).
Applies to
AddControllersWithViews(IServiceCollection, Action<MvcOptions>)
Adds services for controllers to the specified IServiceCollection. This method will not register services used for pages.
public static Microsoft.Extensions.DependencyInjection.IMvcBuilder AddControllersWithViews(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<Microsoft.AspNetCore.Mvc.MvcOptions>? configure);
public static Microsoft.Extensions.DependencyInjection.IMvcBuilder AddControllersWithViews(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<Microsoft.AspNetCore.Mvc.MvcOptions> configure);
static member AddControllersWithViews : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<Microsoft.AspNetCore.Mvc.MvcOptions> -> Microsoft.Extensions.DependencyInjection.IMvcBuilder
<Extension()>
Public Function AddControllersWithViews (services As IServiceCollection, configure As Action(Of MvcOptions)) As IMvcBuilder
Parameters
- services
- IServiceCollection
The IServiceCollection to add services to.
- configure
- Action<MvcOptions>
An Action<T> to configure the provided MvcOptions.
Returns
An IMvcBuilder that can be used to further configure the MVC services.
Remarks
This method configures the MVC services for the commonly used features with controllers with views. This combines the effects of AddMvcCore(IServiceCollection), AddApiExplorer(IMvcCoreBuilder), AddAuthorization(IMvcCoreBuilder), AddCors(IMvcCoreBuilder), AddDataAnnotations(IMvcCoreBuilder), AddFormatterMappings(IMvcCoreBuilder), AddCacheTagHelper(IMvcCoreBuilder), AddViews(IMvcCoreBuilder), and AddRazorViewEngine(IMvcCoreBuilder).
To add services for pages call AddRazorPages(IServiceCollection).
Applies to
Feedback
Was this page helpful?
