how to change routes.MapRoute in mvc3 application


  • Dear all,

    i have solution explorer as follows how can i call Insurance at the time of debugging.


    Tuesday, March 27, 2012 6:18 PM

All replies

  • I guess you are trying to call some method in your InsunranceController 

    The following lines gives you a Greedy routing, it matches everything and invokes Home/Index/{Id} 

    You need to register another route prior to this 

                                    controller = "Insurance",
                                    action = "Index",
                                    id = UrlParameter.Optional

    routes.MapRoute("Default", "{controller}/{action}/{id}", 
    new { controller = "Home", action = "Index" , id = UrlParameter.Optional } ); 

    Tanvir Huda Application Architect/Consultant

    Wednesday, March 28, 2012 1:55 AM
  • When you create a new ASP.NET MVC application, the application is already configured to use ASP.NET Routing. ASP.NET Routing is setup in two places.

    1. ASP.NET Routing is enabled in your application's Web configuration file. There are four sections in the configuration file that are relevant to routing -

    • system.web.httpModules
    • system.web.httpHandlers
    • system.webserver.modules
    • system.webserver.handlers

    These sections should not be deleted otherwise sections routing will no longer work.

    2. Route table is created in the application's Global.asax file. The Global.asax file is a special file that contains event handlers for ASP.NET application lifecycle events. The route table is created during the Application Start event.

    When an MVC application first starts, the Application_Start() method is called. This method, in turn, calls the RegisterRoutes() method. The RegisterRoutes() method creates the route table.

    To change the Default Route -

    new { controller="Survey", action="AddQuestions" });

    Also, keep in mind that the default rote should be the last one.

    Thanks, AT

    Tuesday, April 10, 2012 5:45 AM