I wrote a simple generic method for making POST calls to MVC4 WebApi for use on Windows Phone 8 (But you can use it elsewhere).  The idea is simple: Create one set of generic methods that will take a generic TResultType, an Api Uri, and optionally some data to post and return back a strongly typed response object.

Usage is simple:

This allows you to simply use await to make your MVC4 WebApi calls and get back strongly typed objects.  The Post code uses Newtonsoft Json library to deserialize the response string as an object.

I will package this up as a simple GIT project when I have time and create a nuget package so that everyone can use this simply.

First off, I did not author this from scratch.  Instead, I added some functionality to this class that WindowsPhoneGeek published. I wanted to add CanExecute() and Execute() methods that take no parameter.   Most of the commands I use in my MVVM apps tend to be based on the state of the ViewModel anyway and thus I do not need the parameters.

Here is the DelegateCommand.cs class and the cmds snippet that lets you quickly add a command to any ViewModel.


Command code would look like the following:

The code for the DelegateCommand.cs looks like this: