0
내 생각에 로컬 폴더에서 파일을 다운로드해야합니다. mvc3에서 파일을 다운로드 할 때 발생하는 문제
그래서 내가<img id="trailer" src="../../Images/icon.gif" alt="exists" title="Click on image to Download file"/>
<script type="text/javascript">
$(document).ready(function() {
$('#trailer').click(function() {
var cid = $('#CourseID').val();
var fnm = $('#FileName').val();
var url2 = "/Coursework/DownloadPrtfTrailor" + '?FileName=' + fnm + '&CourseID=' + cid;
$.ajax({
url: url2,
cache: false,
type: 'POST'
});
});
});
</script>
를 다음과 같이 아약스 기능을 썼다 그리고 컨트롤러에 내가 folowing 코드 작성 : 내가 파일을 다운로드 할 수 아니에요이를 통해
[HttpPost]
public ActionResult DownloadPrtfTrailor()
{
string fileName = string.Empty;
string courseID = string.Empty;
string filepath = string.Empty;
if (Request.QueryString != null && Request.QueryString.Count > 0)
{
if (!string.IsNullOrEmpty(Request.QueryString["FileName"]))
fileName = Request.QueryString["FileName"];
if (!string.IsNullOrEmpty(Request.QueryString["CourseID"]))
courseID = Request.QueryString["CourseID"];
}
try
{
var fs = System.IO.File.OpenRead(Server.MapPath("/ePortfolio/" + courseID + "/" + "Icons" + "/" + fileName));
string extn = "application/" + Path.GetExtension(fileName);
return File(fs, extn, fileName);
}
catch
{
throw new HttpException(404, "Couldn't find " + fileName);
}
}
을
하지만, 내가 다음과 같은 액션 링크를 통해 함수를 호출 할 때
@Html.ActionLink("Download", "DownloadPrtfTrailor",
new {CourseID=item.prtfMaster.CourseID, fileName1 = item.prtfMaster.IconFileName})
내가 성공적으로
당신은 ("URL을 파일로") window.open을 사용할 수 있으며 파일이 다운로드됩니다
글쎄 나는 이것을 시도했지만 ... 작동하지 않는다 ... "저장"또는 "열어"를 묻는 창이 나타나지 않는 것처럼 – priya77