What is your prefered way to return XML from an ActionMethod in Asp.net MVC?
- by serbrech
I am displaying charts that load the data asynchronously because the searches are the work to fetch the data is quite heavy. The data has to be return as XML to make the chart library happy.
My ActionMethods return a ContentResult with the type set as text/xml. I build my Xml using Linq to XML and call ToString. This works fine but it's not ideal to test.
I have another idea to achieve this which would be to return a view that builds my XML using the XSLT View engine.
I am curious and I always try to do the things "the right way". So how are you guys handling such scenarios?
Do you implement a different ViewEngine (like xslt) to build your XML or do you Build your XML inside your controller (Or the service that serves your controller)?