2011-04-19 59 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"); 
}