任何人都可以请帮助如何下载 xml(在字符串中)。我正在使用 MVC3
我的代码;
public FileResult Download(string id)
{
var model = service.GetAllDefinitions().First(x => x.ID == id);
var definitionDetails = new StatisticDefinitionModel(model);
string xmlString = definitionDetails.ToXml;
//string presented xml
string fileName = definitionDetails.Name + ".xml";
var stream = new MemoryStream();
var writer = XmlWriter.Create(stream);
writer.WriteRaw(xmlString);
stream.Position = 0;
var fileStreamResult = File(stream, "application/xml", fileName);
return fileStreamResult;
}
但这不起作用。给出错误
错误:
XML 文档必须具有顶级元素。错误处理资源
谢谢,