Opening PDF file from asp.net mvc/script
I am trying to open a pdf file by clicking a button/jquery? Does not work.The ActionLink works though?
<h2>
GetPDF</h2>
<%= Html.ActionLink("works", "GetPDF") %>
<button id="btn">
does not work
</button>
<script type="text/javascript">
$(document).ready()
{
$("#btn").click(
function() {
var url = "/Home/GetPDF";
var data = "";
$.ajax(
{
url: url,
type: 'POST',
data: data,
error: function(err) {
alert('error');
}
}
);
}
)
};
</script>
the controller looks like this:
publ开发者_高级运维ic ActionResult GetPDF()
{
string filename = "mypdff.pdf";
return File(filename, "application/pdf", Server.MapPath("/Content/") + filename);
}
Its because you are making an ajax call. The resulting file is in the ajax object. Perhaps you would like to use window.location(...)
?
精彩评论