开发者

Sending xml to an ASP.NET MVC Action Method Argument

开发者 https://www.devze.com 2023-01-01 04:37 出处:网络
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 d

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

0

精彩评论

暂无评论...
验证码 换一张
取 消