Reputation: 59
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
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
Reputation: 1009
return this.Content(xmlString, "text/xml", System.Text.Encoding.UTF8);
Upvotes: 6