Providing Default Values for a Route in ASP.NET MVC

The default values are useful specially when the entered URL does not contain the items with in the pattern . In these scenarios , the URL can route to the default action or controller.

Providing Default Values for a Route in ASP.NET MVC

Below is a sample code snippet demonstrating the usage of the default values to the route.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

using System.Web.Routing;

namespace MvcApplication1

{

public class RouteConfig

{

public static void RegisterRoutes(RouteCollection routes)

{

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute("NewRoute", "Abundantcode/{controller}/{action}", new { action = "Index" });

}

}

}

In the above example , if the action is missed out in the entered URL , it can use the “Index” action by default.