I have ASP.Net MVC 6 application
I added a route like bellow:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}",
defaults: new {Controllers="Statics", action="Index"}
);
});
but I get error like bellow:
System.InvalidOperationException: The route parameter 'controller' has both an inline default value and an explicit default value specified. A route parameter cannot contain an inline default value when a default value is specified explicitly, consider removing one of them.
Any advise?
After searching and testing I found a good post: http://stephenwalther.com/archive/2015/02/07/asp-net-5-deep-dive-routing
and I updated my routs like bellow it works perfect
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "route2",
template: "statics",
defaults: new { controller = "Departments", action = "Index" }
);
routes.MapRoute(
name: "route3",
template: "statics/SYears",
defaults: new { controller = "SYears", action = "Index" }
);
/*
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}",
defaults: new {controller="Statics", action="Index"}
);
*/
});