Please read the question before flagging as duplicate. I\'m trying to download a file by redirecting with Javascript to a controller action in my ASP.NET MVC3 project. It works
I changed the script with the following:
<script type="text/javascript">
$(function () {
$(".pdf").click(function () {
$.get('@Url.Action("PDFAvailable", "Helper")', { id: @Model.ID }, function (data) {
if(data.message == "File not found.") {
alert(data.message);
} else {
location.href = '@Url.Action("PDF", "Helper", new { id = Model.ID })';
}
});
});
});
</script>
You see, I added a new controller action, which only controls if the file exists and call the file action. This works across all browsers, at least the ones I have. I don't exactly know, but this might be a bug or security precaution in Chrome.