we are starting to use routes for our MVC project, so we basicly replace ActionLink() with RouteLink()
Not sure if you realize that one has nothing to do with the other. ActionLink
and RouteLink
end up calling the exact same method on the UrlHelper
. The only difference is that ActionLink
sends a null
value for route name.
When specifying a route name, only 1 route will be checked to see if it matches the request. Otherwise, all of the routes will be checked in the order they are registered in the route table. The first matching route wins.
The route name is (as would be implied) the name
of the route.
var url = Url.RouteUrl("Tool", new { controller = "Tool", action = "Index" });
That said, it is unclear from your question what you are trying to achieve. Normally, you would use a literal segment in a route to use default route values that only apply to a specific route.
route = routes.MapRoute(
name: "Tool",
url: "tool/{action}",
defaults: new { controller = "Tool", action = "Index" });
In this case, the tool segment in the URL force it to only match URLs beginning with /tool
. It also means there is no way to override the default setting of controller = "Tool"
. But do note that the literal URL has absolutely nothing to do with what is put into the route value dictionary during the request.
Also, you seem to be defeating the purpose of using namespaces by setting the namespaces argument of the route and then setting UseNamespaceFallback
to false
. Unless your application is explicitly using the namespaces in some way, this is senseless.
As for RenderAction
, the framework uses controller
and action
to lookup the child action to render, and passes any values you provide to the method. It builds a new HttpRequest
and then executes it as if you were coming in under that set of route values. As far as routing is concerned, this only matters if you have calls to ActionLink
, RouteLink
, etc. on the view that is rendered (or in any filters that may be in the pipeline on that action). Other than that, this fake request doesn't actually hit the route table. See this post for detailed information about how to use RenderAction
.