HOW TO REGISTERROUTE IN MVC?

Samuel Fernandes

Total Post:159

Points:1117
Posted by  Samuel Fernandes
 897  View(s)
Ratings:
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

            );

        }


  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: How to RegisterRoute in mvc?

    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

                );

            }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!