简体   繁体   中英

Can I hide a part of a route?

I have an AppController and an AccountController. The AppController only has one view, index , which takes query string parameters from the id part of the url.

The default route is as follows: {controller}/{action}/{id} This means for the query string parameters to work properly, the view name has to be in the url. url/view/id

I would like to hide that part of the url and render that view by default, so users need only go to url/id .

I have tried {controller}/{id} and {controller}/index/{id} but neither work.

I think this would work. Set the url as : "{controller}/{id}" and give it a default action parameter:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM