This project is read-only.

Support for Task<ActionResult>

Apr 26, 2012 at 11:51 PM

I've found T4MVC to be an awesome tool, however I've recently switched to using the new C# 5 async/await paradigm and MVC's new Task<ActionResult>, but it seems T4MVC doesn't pick up methods with that new return type.  Any idea when that update will be coming?

Apr 27, 2012 at 12:43 AM

Here was an old thread, though that was not with the Task<T> pattern

I think doing it for Task<T> would be more feasible than with the other pattern, because the method doesn't return void. But it's also not completely straightforward, as we'd need to generate classes that extend Task<T>, the same way that we generate classes that extend ActionResult today.

If someone wants to have a go at it... :)


Oct 15, 2012 at 3:54 AM

Just wondering has there been anything new with this?  Can we use async keyword with T4MVC yet?

Oct 19, 2012 at 2:13 AM

Sorry, short answer is that there isn't. :(

Apr 24, 2013 at 9:36 AM
I'm going to give this a go, shouldn't be too hard.
Just need to change the T4 to support generating a overridden method for Task<ActionResult> but require it to return a Task.FromResult(actionresult) instead, then need to update the extensions to support Task<ActionResult>.


Apr 24, 2013 at 12:17 PM
I was just looking for this too actually.
I think there are going to be more and more people using Task<ActionResult> with MVC, especially considering that entity framework 6 will support async save and async query so that should have a knock-on effet all the way to most controller actions...
Apr 24, 2013 at 4:20 PM
I've added some code to the T4 template today that allows creation of ActionResults for Task based actions -

Just need to create the extensions method for all the Task<ActionResult> overloads.
Apr 24, 2013 at 11:11 PM
Thanks kev_bite, nice job. I hope that makes it back to the master and official nugget.
Apr 25, 2013 at 12:16 AM
Please make sure to send a PR when you have a changes that's ready to go.
May 9, 2013 at 1:08 PM
Hey kev_bite, I've seen you've done some progress.
Do you need some help to get that completed? I'd be happy to help if you need, but I'm not sure if you have some pending changes in your local copies...
May 10, 2013 at 4:39 PM
Its all should be complete and merge in.


May 10, 2013 at 9:38 PM
Actually, Kev's code has been in T4MVC since 3.6, so you should be able to use it today!
May 10, 2013 at 9:39 PM
Here was the pull request.
May 11, 2013 at 6:02 AM
That's awesome thanks guys!