Sending XML to an ASP.NET MVC Action Method Argument

I read a great article recently by Phil Haack on sending JSON to an action method. This was very timely as I wanted to do exactly that in the REST API I've been created for a video hosting website. However, I wanted to make it work with XML as well as JSON.

Phil Haack creates something called a JSON value provider, so I followed his example and created an XML value provider. I've used it on two projects now and it's worked a treat. I thought I'd share it with the world in the hope that it will be useful to others.

Source code

XML Value Provider (C# source)

To get this working in your project you'll need to follow Phil Haack's instructions for his JSON Value Provider.

If anyone has any suggested improvements to the code, then I'd love to hear them.

3 Comments

  • Richard said

    I've been meaning to add licencing info to my code samples for a while.

    I like to licence code samples like this under the MIT licence because it's nice and simple. Lets you do whatever you like with it, but also makes it clear that I accept no responsibility for how the code functions in your system.

    So this code is licenced under the MIT licence.

    I also need to point out that the code is based on samples by Phil Haack on his blog which is licenced under creative commons and allows remixing and commercial use.

Add a Comment