Sending xml to an ASP.NET MVC Action Method Argument
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 don开发者_StackOverflow中文版t see anyone doing this with xml.
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.
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
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.
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
精彩评论