vs 2010 で MVC 3 アプリケーションを作成します。ファイルをダウンロードしようとしました。
これは MVC での私のアクションです。私のコードを見てください。
//[HttpPost]
public FileResult Download(string url, string cnt)
{
if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(cnt))
{
return File(url, cnt);
}
else
{
return null;
}
}
<input type="button" id="@(Model.ControlID)_bio_view" class="changepasswordbutton" value="View" />
そして、.cshtml ファイルに jQuery 関数を作成します。
function ViewFile(url, cnt) {
$.post('@(Url.Action("Download"))?url=' + url + '&cnt=' + cnt)
}
$('#@(Model.ControlID)_bio_view').click(function (e) {
ViewFile($('#bio_file_url').val(), $('#bio_file_url').attr("cnttype"));
});
ダウンロードボタンをクリックすると、この関数が正しく起動されます。ただし、ファイルのダウンロード ウィンドウは表示されません。
助けてください。