Home > DeveloperSection > Forums > How to RegisterRoute in mvc?
Samuel Fernandes
Samuel Fernandes

Total Post:154

Points:1082
Posted on    October-09-2014 12:01 AM

 ASP.NET MVC ASP.Net  ASP.NET MVC 
Ratings:


 1 Reply(s)
 600  View(s)
Rate this:
I would like to rewrite the url from

http://localhost:51639/home/index?id=123
to
http://localhost:51639/home/product
Here is my code in Global.asax.cs

public static void RegisterRoutes(RouteCollection routes)

        {

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

 

            routes.MapRoute(

                "Default", // Route name

                "{controller}/{action}/{id}", // URL with parameters

                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults

            );

        }




Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Supported
Posted on    October-09-2014 12:01 AM

public static void RegisterRoutes(RouteCollection routes)

        {

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

            routes.MapRoute(null, "home/product/{id}", new

            {

                controller = "Home",

                action = "Index",

                id = UrlParameter.Optional

            }

            );

            routes.MapRoute("Default"// Route name

                    "{controller}/{action}/{id}",   // URL with parameters

                    new

                    {

                        controller = "Home",

                        action = "Index",

                        id = UrlParameter.Optional

                    }    // Parameter defaults

            );

        }


Don't want to miss updates? Please click the below button!

Follow MindStick