If you are like any other coder, cutting and pasting snippets should put up a red flag in your mind. You will quickly hit this threshold when creating CRUD-services for MVC 4 applications over and over again. This lead me to create a repository pattern using generic types and base controller classes that I would like to share with you. In the end, below is how my Web API classes look like, which automatically give me create, retrieve, update, and delete functionality:

using MvcWebApp.Helpers;
using MvcWebApp.Models.Data;
  
namespace MvcWebApp.Api
{
    public class SpeakersController : BaseApiController<Speaker>
    {
        //THIS ...
So you have seen the light and ready to make the jump into ASP.NET MVC. But wait! You are not ready to migrate a million lines of code from your legacy Web Forms application? No problem. You can easily integrate MVC 4 into your existing Web Forms application and gradually phase out the legacy stuff over time.

There are many articles and blog posts about this topic. However, most are outdated or take the loooong way. I have a simple, clean solution for you! Here it goes:

  1. Upgrade your Web Forms application to .NET 4 (and Visual Studio 2012 if ...
Sitefinity leaves a lot to be desired with the REST services. For example, take a look at the returned data from Sitefinity's news service out-of-the-box:

{
   "Context":[
      {
         "Key":"String content",
         "Value":"String content"
      }
   ],
   "IsGeneric":true,
   "Items":[
      {
         "Author":"String content",
         "AvailableLanguages":[
            "String content"
         ],
         "CommentsCount":2147483647,
         "DateCreated":"/Date(928164000000-0400)/",
         "DateModified":"/Date(928164000000-0400)/",
         "DefaultPageId":"1627aea5-8e0a-4371-9022-9b504344e724",
         "ExpirationDate":"/Date(928164000000-0400)/",
         "Id":"1627aea5-8e0a-4371-9022-9b504344e724",
         "IsDeletable":...
The ASP.NET MVC 4 Beta includes ASP.NET Web API which makes it very easy to expose data through a REST API in either XML or JSON with very little code.  There are some great tutorials on the asp.net site to get up and running.  After working with MVC 4 for a while, I have discovered a few quirks, so hopefully these tips will save you some time.

XML and IEnumerable Properties

The MVC4 ApiController will automatically detect the request's Content-Type to see if it is expecting application/json or text/xml in the response.  One of my model classes had a collection ...