Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

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

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?
by

2 Answers

Amit8z4mc
you should try this:
return this.Content(xmlString, "text/xml");
pankajshivnani123
If you are only interested to return xml through a request, and you have your xml "chunk", you can just do (as an action in your controller):

public string Xml()
{
Response.ContentType = "text/xml";
return yourXmlChunk;
}

Login / Signup to Answer the Question.