テキストをクリックしたときに特定のファイルをダウンロードする必要があります。通常の [名前を付けて保存] ダイアログでファイルの保存場所を選択する必要があると思いますが、表示されません。リクエストとレスポンスはOKです。
リクエスト/レスポンス ヘッダー
GET /Survey/GetSurveyFile?survey=1085&surveyFileType=2 HTTP/1.1
ホスト: localhost:50518
接続: キープアライブ
ユーザーエージェント: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (Gecko のような KHTML) Chrome/44.0.2403.107 Safari/537.36 OPR/31.0.1889.99
受け入れる: /
X-Requested-With: XMLHttpRequest
======================
HTTP/1.1 200 OK
キャッシュ制御: プライベート
コンテンツ タイプ: アプリケーション/オクテット ストリーム
サーバー: Microsoft-IIS/8.0
X-AspNetMvc-バージョン: 5.2
Content-Disposition: 添付; filename="1052__1183__1291__Variable Header Definition.txt"
X-AspNet バージョン: 4.0.30319
X-SourceFiles: =?UTF-8?B?UzpcVlNTb3VyY2VcUHJvamVrdGVcTU1JXGJmdWVudGVzXE1NSVxNaW5kc2hhcmUuTU1JXE1NSVxTdXJ2ZXlcR2V0U3VydmV5RmlsZQ==?=
永続的な認証: true
X-Powered-By: ASP.NET
日付: 2015 年 8 月 17 日 (月) 14:21:48 GMT
コンテンツの長さ: 333
私のコード:
Javascript
function getfile(filetype) {
var SurveyId = $('#SurveyID').val();
var url = '/Survey/GetSurveyFile';
$.ajax({
type: 'GET',
url: url,
data: { survey: SurveyId, surveyFileType: filetype },
success: function (result) {
// ?
},
error: function (result) {
// handle errors
location.href = "/Home/"
}
});
}
コントローラ
public FileResult GetSurveyFile(string survey, string surveyFileType)
{
try
{
var tmpSurvey = EntityModelDataProvider.GetSurveyByID(int.Parse(survey));
var tmpSurveyFileTypes = EntityModelDataProvider.GetSurveyFileTypes();
var tmpSurveyFileType = tmpSurveyFileTypes.FirstOrDefault(_sft => _sft.SurveyFile_Type_Id == int.Parse(surveyFileType));
var tmpFile = EntityModelDataProvider.GetSurveyFilesBySurveyAndType(tmpSurvey.Survey_PK, tmpSurveyFileType.SurveyFile_Type_PK);
if (tmpFile != null)
{
byte[] fileBytes = tmpFile.SurveyFile;
string fileName = tmpFile.SurveyFile_Name;
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}
else
throw new Exception("File not found!");
}
catch (Exception ex)
{
throw ex;
}
}
どうすれば目的の動作を得ることができますか?