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:

Post a Comment

Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.