4

Whats the best way to return XML data from an MVC controller? I am using Visual Studio 2015. I have tried this but it didn't work:

return new XmlResult(s);
Raja
  • 152
  • 8
Jeremy
  • 59
  • 1
  • 4
  • 1
    have a look at this post https://stackoverflow.com/questions/134905/return-xml-from-a-controllers-action-in-as-an-actionresult This might give you a better picture. – Nasim May 18 '18 at 11:10

2 Answers2

6
return this.Content(xmlString, "text/xml", System.Text.Encoding.UTF8);
Sagi
  • 981
  • 11
  • 15
1

You could use

 public ActionResult Index()
    {
        ViewBag.Title = "Home Page";
        string xmlData="<xml ?>.....";
        return Content(xmlData, "text/xml", System.Text.Encoding.UTF8);
   }

to return a built XML string from an action.

Raja
  • 152
  • 8