Sending xml to an ASP.NET MVC Action Method Argument

早过忘川 提交于 2020-01-02 10:15:44

问题


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:


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.




回答2:


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




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/2906971/sending-xml-to-an-asp-net-mvc-action-method-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!