Mehedi Islam Mehedi Islam - 1 year ago 95
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.


@*<th>File Name</th>*@
@foreach (var file in Model)
@*<a href="#"id="fileId" data-id="@file.Id">@file.Name</a>*@
<a href="@Url.Action("GetFile", "Document", new { Id=file.Id})">@file.Name</a>
<br />
<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>


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 Source
 <div id="frame" class="panel">
<iframe id="iframe" src="@Model.Url" width="870px" height="450px" name="iframe"></iframe>

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download