I'm able to return JSON and partial views (html) as a valid ActionResult, but how would one return an XML string?
+16
A:
You could use return this.Content(xmlString, "text/xml");
to return a built XML string from an action.
John Downey
2009-05-18 17:01:56
This is the reason I love stackoverflow- 100% spot on answers in minutes!
Toran Billups
2009-05-18 17:05:18
Great answer, thanks
Rippo
2010-10-29 08:43:04
+1
A:
For JSON/XML I have written an XML/JSON Action Filter that makes it very easy to tackle without handling special cases in your action handler (which is what you seem to be doing).
aleemb
2009-05-18 18:55:35
For anyone reading this post - definately check out his filter... it works well. +1 to aleemb for sharing!
Mark
2010-09-09 05:58:25
+4
A:
Use the XmlResult from MvcContrib on Codeplex.
Also this seems to be a duplicate question.
MotoWilliams
2009-05-18 19:10:18
not necessarily - the XmlResult class takes an objet *to serialize*, not already-formed XML as a string.
Bobby
2010-02-28 15:53:33
I guess I assumed that since part of the questions referenced JSON that object serialization was part of the equation. I suppose a repository or service could be returning a JSON or XML string to the controller to then be returned to the client from the ActionResult, but that would smell odd to me.
MotoWilliams
2010-03-01 08:00:00