Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return XML from MVC controller

Tags:

c#

asp.net-mvc

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);
like image 314
Jeremy Avatar asked Mar 07 '23 04:03

Jeremy


2 Answers

return this.Content(xmlString, "text/xml", System.Text.Encoding.UTF8);
like image 128
Sagi Avatar answered Mar 08 '23 18:03

Sagi


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.

like image 21
Raja Avatar answered Mar 08 '23 20:03

Raja