[英]Generating complex raw xml from asp.net mvc c#
在我的ASP.net c#MVC项目中,我想获取通过读取DB生成的原始XML。
我收到了XML响应,但问题是我的完整XML在字符串中显示为纯字符串
为了使此响应成为格式正确的XML输出,我应该更改什么?
以下是我得到的
public override void ExecuteResult(ControllerContext context)
{
if (this.objectToSerialize != null)
{
context.HttpContext.Response.Clear();
var xs = new System.Xml.Serialization.XmlSerializer(this.objectToSerialize.GetType());
context.HttpContext.Response.ContentType = "text/xml";
context.HttpContext.Response.ContentEncoding = UTF8;
xs.Serialize(context.HttpContext.Response.Output, this.objectToSerialize);
}
}
确定要返回纯文本吗? 当接收到XML时,许多浏览器仅在XML内部显示文本。
如果在浏览器中查看源代码(IE8:右键单击并选择“查看源代码”,类似于Firefox和Chrome),它是XML还是纯文本?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.