如何在ActionResult中返回XML类型

非常简单,请直接看代码:

public ActionResult Index()
{
    //返回一个XML类型
    string xmlString = "<?xml version=\"1.0\" encoding=\"gb2312\" ?><tree id=\"0\"><item text=\"北京欢迎你\"/></tree>";
    return this.Content(xmlString, "text/xml");
}

注意事项:如果想在XML正常显示汉字,则编码要用gb2312。

效果如下图:

image

原文地址:https://www.cnblogs.com/hearticy/p/1617189.html