简体   繁体   中英

Custom routes for controller with Html.ActionLink and Url.Action

Is it possible to create a exception in de Url.Action function for a certain controller?

We have a controller for Html pages in a database that can be accesses with a certain ID. For example /Page/1 .

But instead of '/Page/1' we want to have '/seo-frienly-url' without the controller name or ID.

I know it is possible to add Custom routes in MVC, but with a lot of routes it gets slow when resolving them, so i want to make an exception for a certain controller.

The routing already works because we have changed the default route to '/{seo-page-title}' and linked it to a controller / action to get the html by page title instead of ID.

You can pass a route name to UrlHelper.RouteUrl . That way you can pick which route the URL must be built from.

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