나는 어제 비슷한 질문을 올렸지 만 결과를 얻지 못했습니다. 내 검도 그리드에 데이터를로드 한 후 다운로드를 클릭하면 파일을 다운로드하려고하지만 결과를 반환하지 않습니다. 내가 다운로드하는 폴더가 프로젝트 솔루션이 아닌 서버에 있습니다. 버튼을 클릭하지 않고 다운로드를 테스트하는 컨트롤러를 만들었지 만 작동하지만 검도 버튼을 클릭하여 다운로드하고 싶습니다. 그리드아약스 호출에서 파일을 다운로드하고 강제로 결과를 다운로드 할 수 있습니다.
function showDetails(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
DownloadIndexController(dataItem.possID);
}
컨트롤러에 Ajax 호출
function DownloadIndexController(possID) {
$.ajax({
url: '@Url.Action("DownloadIndex", "Poss")',
type: "GET",
data: { possID: possID },
dataType: "json",
success: function (data) {
window.location = '@Url.Action("DownloadIndex", "Poss")';
}
})
}
컨트롤러
public ActionResult DownloadIndex(int possID)
{
string Filelocation = "myserverlocation"
FileContentResult ff = null;
try
{
OnePossModel md = new Models.OnePossModel();
JsonParamBuilder myBuilder = new JsonParamBuilder();
myBuilder.AddParam<Guid>("submittingUserID", System.Guid.Parse(User.Identity.GetUserId()));
myBuilder.AddParam<int>("possID", Convert.ToInt32(possID));
string jsonReq = Models.JsonWrapper.JsonPOST(ApiBaseUrl + ApiPOSSSubBaseUrl + "/WritePOSSFile", myBuilder.GetJSonParam());
string possFilename = Models.DeserialiseFromJson<string>.DeserialiseApiResponse(jsonReq);
possFilename = possFilename.Replace(",", ",");
string x = Filelocation + possFilename.ToString();
var type = System.Net.Mime.MediaTypeNames.Application.Octet;
byte[] fileBytes = System.IO.File.ReadAllBytes(x);
string myfileName = possFilename;
ff = File(fileBytes, type,myfileName);
Response.AppendHeader("Content-Disposition", "attachment; filename=" + myfileName);
Response.BinaryWrite(fileBytes);
return ff;
}
catch (Exception ex)
{
throw ex;
}
}
에서 선택한 아이디를 얻기를위한 콘솔 없음 오류가
기능 컨트롤러에서
를? –
당신은 Response.BinaryWrite (fileBytes)를 제거해야한다는 뜻입니다; –