내가 생각 해낸 대답은 같은 일반적인 아니라, 아직이 솔루션은 작동 : 대안 들어,이 질문을 참조하십시오. 여기
public class MyController : Controller
{
public void Index()
{
PropertyBag["includeZeroBalances"] = false;
PropertyBag["toDate"] = DateTime.Today.ToShortDateString();
}
public void Download(bool includeZeroBalances, DateTime toDate)
{
MyProxy proxy = GetProxy();
byte[] file = proxy.GetFile(includeZeroBalance, toDate);
PropertyBag["downloadurl"] = "data:application/zip;base64," + System.Convert.ToBase64String(file);
}
}
다음은 인덱스 페이지
${Form.FormTag({@action: 'Download'})}
<table>
<tr>
<td>${Form.LabelFor("toDate", "To Date (yyyy/mm/dd):")}</td>
<td><input type="text" id="toDate" name="toDate" value="${?toDate}" /></td>
</tr>
<tr>
<td>${Form.LabelFor("includeZeroBalances", "Include Zero Balances:")}</td>
<td>${Form.CheckboxField("includeZeroBalances")}</td>
</tr>
<tr>
<td> </td>
<td>${Form.Submit("Download", {@class: 'submitb'})}</td>
</tr>
</table>
${Form.EndFormTag()}
입니다 또한 새 창에서 파일을 다운로드 자동화하기 위해 자바 스크립트를 추가 할 수 있습니다 다운로드 페이지
<table>
<tr>
<td>Your file has been generated successfully. <a href="${downloadurl}">Click here</a> to download your file</td>
</tr>
</table>
입니다. 파일을 저장하려면이 방법을 사용
document.Ready(function()
{
window.open("${downloadurl}");
});
장점 : 어떤 파일이 서버에 저장되지 않습니다. 약 300kb 이상의 파일을 다운로드 할 때 오버 헤드가 약간 낮아집니다. 응답 데이터를 덮어 쓰지 않으므로보기가 정상적으로 렌더링됩니다.
이 방법을 사용하여 파일을 저장하는 데 따른 단점 : 모든 버전의 브라우저에서 사용하기에 충분하지 않습니다. 정적 파일에 사용하는 경우 파일이 변경되면 파일 내용이 uri에 포함되어 있기 때문에 다시 생성해야합니다.
이 문제로 인해 다른 사람들에게 도움이되기를 바랍니다.나는 직설적 인 해결책이없는 수많은 게시판에서 이런 유형의 질문을 보았습니다.
안녕하세요, Mauricio, 제공하신 링크와 통찰력에 감사드립니다. 불행히도, 이것은 제가 찾던 것이 전부가 아닙니다. –
@ROFFELPOMP : 글쎄, 네 대답에 정확히 무엇을 했나. –