2011-10-01 2 views
6

보기 (MVC)를 파일 만 은 대내보내기 엑셀 사실 내가 구현 한 엑셀로보기 데이터 내보내기에 내가 가진

return new FileContentResult(fileContents, "application/vnd.ms-excel"); 

을 사용할 때 내 의심의 여지가있다

return File(fileContents, "application/vnd.ms-excel"); 

및 각 방법에서 다운로드 가능한 파일 이름을 어떻게 설정할 수 있습니까?

예 1 :

public ActionResult ExcelExport() 
{ 
    byte[] fileContents = Encoding.UTF8.GetBytes(data); 
    return new FileContentResult(fileContents, "application/vnd.ms-excel"); 
} 

예 : 2

public ActionResult ExcelExport() 
{ 
    byte[] fileContents = Encoding.UTF8.GetBytes(data); 
    return File(fileContents, "application/vnd.ms-excel"); 
} 

답변

9

당신은 & FileResult 여기 FileContentResult의 차이점에 대해 읽을 수 있습니다 : What's the difference between the four File Results in ASP.NET MVC

당신이

같은 파일 이름을 지정할 수 있습니다
return new FileContentResult(fileContents, "application/vnd.ms-excel") { FileDownloadName = "name.xls" }; 

// or 

// note that this call will return a FileContentResult object 
return new File(fileContents, "application/vnd.ms-excel", "name.xls");