Map Routes using Route Class in MVC


In MVC application, we can register routes in RouteCollection using RouteConfig. This RouteConfig is called using Application_Start of application.
RouteConfig is configured as below


routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "ProgramConfigEditor", action = "Index", id = UrlParameter.Optional }
            );

We can register route of the application using Route Class as below. After creation of Route collection, it will move to MvcRouteHandler object.


Route route = new Route("{controller}/{action}/{id}",
                new RouteValueDictionary { { "controller", "ProgramConfigEditor" }, { "action", "Index" }, { "id", "1" } }, new MvcRouteHandler());

            routes.Add(route);

Comments

Popular posts from this blog

How to Add HttpModule in MVC5 Application

How to convert a string with multiple comma separated values to rows in SQL Server