Monday, September 16, 2013

URL routing in ASP.NET MVC

In ASP.NET MVC, the routing is very easy. By examine the URL, its automatically find the controller and then actions.



But, to select a single controller for all kinds of URL, followings can help

           routes.MapRoute(
                "Single",
                "{page}",
                new { controller = "Single", action = "Single" }
            );
            routes.MapRoute(
                "SingleChild",
                "{page}/{child}/{*ignore}",
                new { controller = "Single", action = "Child" }
            );
            routes.MapRoute(
                null,
                "",
                defaults: new { controller = "Single", action = "Home" }
            );

No comments: