我正在尝试做什么 - 当用户单击链接时,从RavenDB获取附件并自动为用户打开它。在ASP.NET MVC的用户界面中为用户打开附件
单击链接 - 我通过view/ajax将附件的附件标识(已保存在RavenDB中)传递给控制器方法。一旦进入控制器方法,我想获取附件并显示/打开用户的附件。
查看:
<a href onclick="GetAttachment('<%= Model.Id %>');"> See attachment </a>
阿贾克斯/ JS
function GetAttachment(id) {
$.ajax({
type: 'POST',
url: '/ControllerName/GetMethod',
data: id,
contentType: 'application/json; charset=utf-8',
success: function (msg) {
if (msg.Success) {
}
else {
}
}
});
}
控制器:
public string GetMethod(string id)
{
var dbCommands = session.Advanced.DatabaseCommands;
var attachment = dbCommands.GetAttachment(id);
//Here - How do I use above lines of code to get hold of the
// attachment and open it for the user.
}
谢谢你的帮助。
什么是附件类型?它是流还是其他?在所有情况下,您需要从Action中返回FileResult。 – 2012-08-01 14:41:24
保存其转换成流..并保存为字节信息..它可以是任何类型的文件.. .pdf或.doc等 – ZVenue 2012-08-01 14:43:34