Mehedi Islam Mehedi Islam - 4 months ago 14
HTML Question

How to show document file into iframe return from href action lnk?

I have an index page index.cshtml.Which is showing a list of document file and with beside an iframe.I want to show document file into iframe when i click any one of a list.But when i click anyone of a document list shows another page.

index

<table>
@*<th>File Name</th>*@
@foreach (var file in Model)
{
<li>
@*<a href="#"id="fileId" data-id="@file.Id">@file.Name</a>*@
<a href="@Url.Action("GetFile", "Document", new { Id=file.Id})">@file.Name</a>
</li>
<br />
}
</table>
<div id="frame" class="panel-default" >
<div id="frame" class="panel" >
<iframe src="@Url.Action("GetFile", "Document", new { Id=@Model.First().Id})" width="870px" height="450px"></iframe>
</div>
</div>


Controller

[HttpGet]
public FileStreamResult GetFile(int? Id)
{
if (Id == null)
Id = 4;
string fileName = _manager.FileNameSearch(Id);
string filePath = ConfigurationManager.AppSettings["FilePath"] + fileName;
FileStream fs = new FileStream(Server.MapPath(filePath), FileMode.Open, FileAccess.Read);
return File(fs, "application/pdf");
}

Answer
 <div id="frame" class="panel">
<iframe id="iframe" src="@Model.Url" width="870px" height="450px" name="iframe"></iframe>
</div>    

 <li>
<a href="@Url.Action("GetFile", "Document", new { Id = Model.Id })" target="iframe">@Model.Name</a>