How to Route /About to /Home/About

后端 未结 2 1044
故里飘歌
故里飘歌 2021-01-14 10:33

I am just getting started with ASP.NET MVC and it\'s great! However, I don\'t quite understand setting up routes.

How do I route ~/About to ~/Home/About?

/Vi

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-14 11:05

    If you want to explicity setup a route for it, you can do something like this:

    routes.MapRoute( 
                "AboutRoute", 
                "About", 
                new { controller = "Home", action = "About" }  // Parameter defaults 
        );
    

    I think thats what you want to do? I.e. have /About handled by the home controller?

    The default route (as below) handles /Home/About

        routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );
    

提交回复
热议问题