2011-04-19 44 views

回答

0

你可以使用Content-Disposition头,并指定attachment属性,它会提示用户另存为对话框:

public ActionResult Download() 
{ 
    var cd = new ContentDisposition 
    { 
     FileName = "foo.xml", 
     Inline = false 
    }; 
    Response.AppendHeader("Content-Disposition", cd.ToString()); 
    var xml = Encoding.Default.GetBytes("<root>some content</root>"); 
    return File(xml, "text/xml"); 
}