Return XML from a controller's action in as an ActionResult?

Ken Randall picture Ken Randall · Sep 25, 2008 · Viewed 93.4k times · Source

What is the best way to return XML from a controller's action in ASP.NET MVC? There is a nice way to return JSON, but not for XML. Do I really need to route the XML through a View, or should I do the not-best-practice way of Response.Write-ing it?

Answer

Petr picture Petr · Dec 1, 2010
return this.Content(xmlString, "text/xml");