window.href.location not working in chrome

前端 未结 1 406
走了就别回头了
走了就别回头了 2021-01-27 08:47

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

相关标签:
1条回答
  • 2021-01-27 09:15

    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.

    0 讨论(0)
提交回复
热议问题