0
我通过使用自定义的ActionResult返回从控制器操作XML:应用XSLT到XML在Asp.NET MVC
public class XmlActionResult : ActionResult
{
/// <summary>
/// This class is a custom ActionResult that outputs the content of an XML document to the response stream
/// </summary>
private readonly XDocument _document;
public Formatting Formatting { get; set; }
public string MimeType { get; set; }
public XmlActionResult(XDocument document)
{
_document = document;
MimeType = "text/xml";
Formatting = Formatting.None;
}
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.Clear();
context.HttpContext.Response.ContentType = MimeType;
using(var writer = new XmlTextWriter(context.HttpContext.Response.OutputStream, null)
{
Formatting = Formatting
})
_document.WriteTo(writer);
}
}
这个输出XML树浏览器。我有一个转换XML的XSL文件,我将如何将样式表应用于XML输出?
请停止将“ASP.NET MVC”简称为“MVC”。一个是框架,而另一个是独立于语言的设计模式。这就像打电话给IE - “互联网” –
这是一个公平的点,道歉! –
您想在服务器上或客户端浏览器上应用XSLT转换的位置? –