Just in case anybody is reading this, and has the same problem.
I got to the bottom of it, and now realise why I was getting different
flavours of the same problem:
1, The basic RedirectToAction call was not working because it doesn't
account for Areas. S#arp has an extension method for
Html.ActionLinkForAreas, but I suggest that an extension to controller
for RedirectToAction, or perhaps an extension to UrlHelper - i.e. an
extension accessible from the controller (context) that takes Area's
into consideration. I can provide the code here if desired cathal[DOT]
mchale[AT]gmail
2, It doesn't work for posts to a controller that originate from a
partial rendered via Html.RenderAction. E.g. I have my search partial
rendered on the home page via Html.RenderAction. When this posts and
you try to generate a route URL, it just can't map it for some reason
(something to do with the context) - but anyhow, I can live with it
being that the only time I have to Redirect(HardCodedUrl) is for
RenderAction posts. For everything else 1, works in a strongly typed
manner.
3, To make things really clean, I've elaborated on the custom
ModelBinder concept. With a custom ModelBinder for SearchCriteria, I
can simply specify action methods with SearchCriteria as a parameter,
and the custom binder strips the route parameters (in this case query
string params) and converts to a SearchCriteria object.
I took this a step further by having my custom binder inherit an
interface IRoutableObject<T> defining the method: RouteValueDictionary
GetRouteValuesFor(T routeModel); I incorporated this logic into my
redirect extension in 1, and now I can
RedirectToAction<SearchController>(x => x.Results(new SearchCriteria
{ SelectedCountry = "Ireland", SelectedAge = "20" })) - and the
redirect extension does what it used to do, but also checks if the
object is a RoutableObject - if so it'll add the appropriate route
parameters for the objects state.
Cheers,
Cathal.