The main point to consider when using MVC with EPiServer, is that in MVC a URL maps to controller and an action.
In EPiServer this isn't case. A URL will point to a page type with a specific ID.
Hi Gayathri,
Episerver also maps to controller and action; it is just a bit more hidden :) The url for a page of type T will typically be routed to the single controller that implements PageController<T>. UrlResolver will resolve to the default action for the controller, which is normall the Index action.
My challenge is to have UrlResolver resolve to an action other than the default one, without the query string argument. The url relative path for any non-default action would be the same as for the default action, with the action name as the next segment.
Without studying the EPiServer routing code in detail, one thought that pops in to my head is casing. What if you try with 'action' instead of 'Action', that is like:
UrlResolver.Current.GetUrl( somePage.PageLink, null, new { action = nameof(SomeController.SomeActionOtherThanIndex) })
Hi Johan,
Thanks for the suggestion! Casing did not help, but in the process of trying it, I noticed that VirtualPathArguments has a separate property for the action. I'd managed to totally overlook it before... When setting that property, the url was resolved like I wanted :)
Cheers,
Per Atle
Hi,
I'm trying to override the action for the url that UrlResolver returns, by using this code
and
but haven't been able to return an url that does not also include the action in the query string, that is, I end up with the relative path "/path/to/page//?Action=<>action_name>". My hack for now is to remove the query string parameter by using QueryCollection.Remove from EPiServer.UrlBuilder, but I'd much rather prevent the cause than handle the effect.>
Any pointers?