Jeremy
Jeremy

Reputation: 59

Return XML from MVC controller

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);

Upvotes: 4

Views: 4377

Answers (2)

Raja
Raja

Reputation: 152

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.

Upvotes: 1

Sagi
Sagi

Reputation: 1009

return this.Content(xmlString, "text/xml", System.Text.Encoding.UTF8);

Upvotes: 6

Related Questions