Thursday, November 15, 2012

ASP.Net MVC–Returning XML

If you need to return xml content from an MVC controller, the easiest way to do it is to use the “Controller.Content” method.

public class TestController : Controller
{
        public ActionResult Index()
        {
             string result = “<books><book/></books>”
             return this.Content(result, "text/xml");
        }
}

No comments: