Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Unassigned: URL Smart Generation (ActionLink, etc) [1292]

$
0
0
I've currently run into a scenario where I'd like to re-use much of an existing controller and not have to worry about creating new files.

In my area registration on an MVC3 website I have the following code:

```
context.MapRoute(
"AdminMdsWebRule",
"Admin/MDS/WebRule/{action}/{id}",
new { action = "Index", controller = "WebRule", id = UrlParameter.Optional, interfaceModel = typeof(UIAssessment) },
new string[] { "WebUI.Controllers" }
);

context.MapRoute(
"AdminUBWebRule",
"Admin/UB/WebRule/{action}/{id}",
new { action = "List", controller = "WebRule", id = UrlParameter.Optional, interfaceModel = typeof(MasterUBClaim) },
new string[] { "WebUI.Controllers" }
);
```

Essentially this uses the pattern matching feature to properly point to the same controller in the base of the application, it also uses this opportunity to create a route value that identifies a class type to be used as an interface.

The issue comes when the Helpers are generating URLs, because the route map has two entries with the same controller name, when the url is generated it takes the first one and uses that as the source for generating the url.

It would be nice if it tried to apply the pattern matching to instances where multiple paths are possible.
Comments: Hi Erik, Both ActionLink and RouteLink ultimately call into the same routing code. It's just that ActionLink will try and match each route, first to last, until it finds a matching route (which might sometimes not be the route you wanted). On the other hand, RouteLink will go directly to the named route (names are unique, so there can be only one), and apply the provided parameters to that pattern only (it might still not match, but either you get back the URL you wanted, or you get back nothing - you will never get back the wrong URL). Depending on your scenario you might still be able to use RouteLink by passing in the name as a parameter from whoever called the CSHTML page. When rendering a partial view you can pass in additional ViewData and then consume that from within the reusable view. Thanks, Eilon

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>