使用asp.net mvc打开字节流文件
在我的 asp.net mvc 应用程序中,我将
<%=Html.Hidden("attachmtId", item.ILDAttachmentId) %>
<%=item.ILDAttachmentName %>
jquery部分如下
$(文档).ready(function() {
$(".thumpimage").click(function() {
var attchmtId = $("#attachmtId").val();
警报(attchmtId);
$.post('/Instruction/OpenInstnDoc', { attchId: attchmtId });
});
});
控制器中的函数是
public ActionResult OpenInstnDoc(int attchId)
{
附件 objAttach = new Attachment();
objAttach = objAttach.GetAttachmentById(attchId);
byte[] theData = objAttach.BinaryFile;
Response.AddHeader("内容长度", theData.Length.ToString());
Response.AddHeader("content-disposition", "inline; filename=" + objAttach.AttachmentName + "");
返回文件(theData,objAttach.MineType);
}
我无法打开该文件。谁能帮我解决这个问题吗?
Im my asp.net mvc application I have a
My aspx page has the following html in it:
<li class="thumpimage">
<%=Html.Hidden("attachmtId", item.ILDAttachmentId) %>
<img src="<%=imgurl %>" alt="test" height="81" width="76" />
<span class="thumb_descrp">
<%=item.ILDAttachmentName %></span></li>
The jquery part is as follows
$(document).ready(function() {
$(".thumpimage").click(function() {
var attchmtId = $("#attachmtId").val();
alert(attchmtId);
$.post('/Instruction/OpenInstnDoc', { attchId: attchmtId });
});
});
And the function in the controller is
public ActionResult OpenInstnDoc(int attchId)
{
Attachment objAttach = new Attachment();
objAttach = objAttach.GetAttachmentById(attchId);
byte[] theData = objAttach.BinaryFile;
Response.AddHeader("content-length", theData.Length.ToString());
Response.AddHeader("content-disposition", "inline; filename=" + objAttach.AttachmentName + "");
return File(theData, objAttach.MineType);
}
I am not able open the file. Can anyone help me on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法使用 ajax 将文件内容流式传输到浏览器并期望收到文件打开/保存对话框的提示。不要调用 $.post,而是尝试
You cannot use ajax to stream file content to the browser and expect to be prompted with a file open/save dialog. Instead of the call to $.post, try