If you created an empty project, or you still don't have mvc configured in your application, you can add dependency:
"Microsoft.AspNetCore.Mvc": "1.0.1"
To your project.json
file under "dependencies"
.
And register MVC middleware in your Startup class:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddMvc();
}
Note that we have both services.AddMvc()
and services.AddMvcCore()
. If you are starting with asp.net core
, or you want it the way it is, you should keep with services.AddMvc()
. But if you want an advanced experience, you can start with a minimal MVC pipeline and add features to get a customized framework using services.AddMvcCore()
. See this discussion for more information about AddMvcCore
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddAuthorization()
.AddJsonFormatters(j => j.Formatting = Formatting.Indented);
}
Now you can tell your application builder to use the mvc:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
app.UseMvc();
}
or with default routing:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});