How to set the default controller in MVC4?
I've tried adding the below code to the Global.ascx but it said "Only assignment, call, increment, decrement, and new object expressions can be used as a statement", seems it can't find the "route", did I put it on the wrong place?
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index",
id = UrlParameter.Optional }
);
Below is the screenshot:

Take a look at App_Start/RouteConfig.cs file. This is where you will be able to configure routes in the way you want.
There, you will find code similar to this:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
you need to put this code inside RouteConfig.cs under App_Start.
check ASP.NET MVC 4: Where Have All The Global.asax Routes Gone?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With