TransferToAction for ASP.NET MVC 5
In addition to the RedirectToAction
method inside a Controller
, I want to be able to use a Server.Transfer
inside my actions.
This can be useful, if you want to redirect without changing the URL(routing).
I also want to ensure that an action is only accessible by a transfer request - similar to ChildActionOnly
-attribute.
After searching for an existing solution without success (not a complete solution) I came up with the following code.
The usage is very simple:
The transfer implementation is inside a custom ActionResult
and can be easily called trough an extension.
To make the TransferActionOnly
-attribute possible, a query string marker is used.
You can do anything you want with this code, but don’t hold me liable :)