HOW ROUTE TABLE IS CREATED IN ASP.NET MVC4?

Vijay Shukla

Total Post:81

Points:405
Posted by  Vijay Shukla
 11304  View(s)
Ratings:
Rate this:
  1. Vijay Shukla

    Post:81

    Points:405
    How route table is created in ASP.NET MVC4?

    When an MVC4 application starts, the Application_Start() method is called. This method is calls the RegisterRoutes() method. Which is  creates the route table.

  1. Abhishek Singh

    Post:2

    Points:10
    How route table is created in ASP.NET MVC4?

    you need to register Routes in the Application_Start() method like this


    protected void Application_Start()
    {
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    }

    After that you need to override the method of RouteConfig Class like this
     public static void RegisterRoutes(RouteCollection routes)
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
                //routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
                routes.MapRoute(
                   name: "Blog",
                   url: "Blog/{id}/{Title}",
                   defaults: new { controller = "Blog", action = "Index", id = UrlParameter.Optional });

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


                routes.MapRoute(
                   name: "Articles",
                    url: "Articless/{article_id}",
                    //url: "{controller}/{article_id}",
                   defaults: new { controller = "Articles", action = "Index", article_id = UrlParameter.Optional });
                // used for blog URL

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

                
                

            }


    From this you need URL Routing in MVC 4

Answer

NEWSLETTER

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