Search This Blog

Monday, August 5, 2019

Routing in MVC 4 and 5


  •  Routing  is a pattern matching system
  •  Routing maps incoming request (from browser) to a particular resource(controller and action   Method)
  Every Request come routing   match Route Table then  call particular  controller

 Route Table
  We define route for each action method
  All the routes  are stored in route table
  Each incoming request mapped to this route table




There are 2 type use Routing in MVC Application
Traditional Way
Attribute routing

                                                     Traditional Way

In  a traditional   way  routing define route particular file routeconfig.cs with in app-start folder
Routeconfig.cs  Code

   public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "allstudents",
                url: "students",
                defaults:new {controller= "Student" ,action= "GetAllStudent" }
             
           );
            routes.MapRoute(
                 name: "Students",
                 url: "students/{id}",
                 defaults: new { controller = "Student", action = "GetSingleStudent" },
                   constraints: new { id = @"\d+" }
            );
            routes.MapRoute(
              name: "StudentsAddress",
              url: "students/{id}/Address",
              defaults: new { controller = "Student", action = "StudentAddress" }
         );
         routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
           
        }
    }







1 comment :

Bollywood Hungama said...

Check out the latest Bollywood news, new Hindi movie reviews, box office collection updates

Thor Love And Thunder Full Movie Download & Review
Maidaan Full Movie Download & Review