What I am trying to do – When user clicks on a link, get the attachment from RavenDB and open it automatically for the user.
On Click of a link – I pass the attachment id of a attachment (already saved in RavenDB) to the controller method via view/ajax. Once inside the controller method, I want to get the attachment and display/open the attachment for the user.
View :
<a href onclick="GetAttachment('<%= Model.Id %>');"> See attachment </a>
Ajax/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 {
}
}
});
}
Controller :
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.
}
Thank you for the help.
Something like this:
Controller:
View:
You need get MemoryStream of file from database or transfer your file into MemoryStream