views:

79

answers:

4

Is it possible to send POX (plain old xml) into an action and have that action perform model binding to an object for you. Have seen this done with JSON but dont see anyone doing this with xml.

+1  A: 

You can achieve this by creating your own model binders.

you can get idea from the following links.

http://odetocode.com/blogs/scott/archive/2009/04/27/6-tips-for-asp-net-mvc-model-binding.aspx

http://odetocode.com/blogs/scott/archive/2009/05/05/iterating-on-an-asp-net-mvc-model-binder.aspx

Elangovan
+1  A: 

Looking at doing a similar thing, but with JSON. I think you could also use a ActionFilterAttribute for this purpose. An example is shown here.

Igor Zevaka
A: 

I have found a cleaner way to do this than Igor's suggestion. Phil Haack has an article ( Sending JSON to an ASP.NET MVC Action Method Argument) that uses a JsonValueProviderFactory from MVC futures. So I think all I need to do is create a XmlValueProviderFactory which will allow default model binding to occur. Will update when I get this to work

Noel
I had the same idea. It took me a while to get it working though. I've included a link to what I came up with in my answer.
Richard
A: 

Phil Haack did this for JSON using a JSON Value Provider. Inspired by that and starting with his source code I created an XML Value Provider Factory.

You can download the source for my XML Value Provider here.

Richard