AddRouteValues to Task<ActionResult>

Jul 19, 2013 at 2:54 PM
How can I add route values to an async mvc method returning a task?
Coordinator
Jul 19, 2013 at 9:43 PM
Maybe just with .Result.AddRouteValues(...)?
Jul 20, 2013 at 2:08 PM
I don't have this function available. Can you see it? From which namespace is it?
Coordinator
Jul 21, 2013 at 3:21 PM
It's an extension method on ActionResult.
Jul 21, 2013 at 9:27 PM
I guess you didn't read my question. It says that I am using an ASYNC method. As I state in the title this returns a Task<ActionResult> and not just an ActionResult. So this extension method is of no use.

Anyone else? Am I the only one using T4MVC with async methods?
Coordinator
Jul 21, 2013 at 10:08 PM
You missed my answer above: .Result.AddRouteValues(...).
Jul 21, 2013 at 10:19 PM
Well, Task.Result of a Task<ActionResult> of course is of type ActionResult thus the normal extension method is available there also. But I doubt that this works in that usage scenario. How would I use that? Let's say I have a method like "public Task<ActionResult> MyMethod(string myValue)" would I just say "Routes.Controller.MyMethod("xyz").Result.AddRouteValues(...)"? I understand that this compiles but can you confirm that it works?
Coordinator
Jul 21, 2013 at 11:21 PM
Yes, I suspect this will work. Just use standard T4MVC syntax except add .Result
Jul 23, 2013 at 3:08 PM
I just tested this and it really does work!

I was so convinced that it wouldn't that I refrained to even think in that direction. Sorry about that and thanks for your help.
Coordinator
Jul 31, 2013 at 9:55 PM
Glad it worked! T4MVC works in somewhat unusual ways, with 'fake' calls that are only used to build up route values.