i want to display pdf and docx in browser or in div. I have done, in which i could display pdf file, but docx file doesn't work with this way
I have database in which i am saving files in binary format and i want to retrive that binary format and display, the code i have shared is working with pdf file, but i want to display both pdf or docx, as i have both files in my database
Controller
private DiagnosticDetailModel GetFileList(int id)
{
var DetList = db.DiagnosticDetailModels.Where(p => p.Id == id).FirstOrDefault();
return DetList;
}
[HttpGet]
public ActionResult RetrieveFile(int id)
{
DiagnosticDetailModel diagnosticDetailModel = GetFileList(id);
byte[] img = diagnosticDetailModel.FileContent.ToArray();
Response.AppendHeader("Content-Disposition", "inline");
return File(img, "application/pdf");
}
Index.cshtml
<table id="Jdatatable" class="table css-serial" style=" border: 1px solid #5bc0de; border-radius:5px; box-shadow: 2px 2px black;">
<thead style="background-color:#5bc0de; color:white;font-size:14px;">
<tr>
<th>#</th>
<th>
Diagnostic Name
</th>
<th>
Registration Date
</th>
</th>
<th>View Report</th>
</tr>
</thead>
<tbody style="font-size:12px;">
@foreach (var item in Model)
{
<tr>
<td></td>
<td>
@Html.DisplayFor(modelItem => item.DiagnosticName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date)
</td>
<td>
@Html.ActionLink("View", "RetrieveFile", new { id = item.Id }, new { @class = "btn btn-primary btn-sm fa fa-eye", @style = "color:white;background-color:#5bc0de;", @target = "_blank" })
</td>
</tr>
}
</tbody>
</table>