Please visit DEMANDDRAFT.SHOP for quality of products...

Ad

Search This Blog

Thursday, May 21, 2015

How to bind the Iframe control from Data base when View button click in WebGrid Control in MVC4 with C#

C# Source Code 
------------------------------------------------------------------------------------


public ActionResult ViewPDFDocument(int? Id)
        {
            var SRepository = new SRepository();
            var downloadFileName = SRepository .GetDownloadFileName(Id);
            byte[] imageByteData = SRepository .GetPdfFileContent(Id);
            string imageBase64Data = Convert.ToBase64String(imageByteData, 0, imageByteData.Length);
            MemoryStream workStream = new MemoryStream();
            workStream.Write(imageByteData, 0, imageByteData.Length);
            workStream.Position = 0;
            Response.AppendHeader("Content-Disposition", "inline; filename=" + downloadFileName.ToString().Trim());
            Response.ContentType = "application/pdf";
            return File(workStream, "application/pdf", downloadFileName.ToString().Trim());
        }


 ------------------------------------------------------------------------------------------------
In the View  :-

<div id="">
        <table >
            <tr>
                <td align="left" colspan="2" style="vertical-align:top;">
                    @grid.GetHtml(tableStyle: "webgrid-table",
                        headerStyle: "webgrid",
                        footerStyle: "webgrid-footer",
                        alternatingRowStyle: "webgrid-alternating-row",
                        rowStyle: "webgrid-row-style",
                    columns:
                     grid.Columns
                        (
                            grid.Column("CompanyName", "Company Name"),
                            grid.Column("FileName", "FileName "),
                            grid.Column("FileUploadDate", "File Uploaded Date"),
                           grid.Column(format: @<a href="~/SupController/ViewPDFDocument/@item.FileUploadId" target="iframe_a" style="color:blue;">&nbsp;View&nbsp;   </a>)
                        ))
                 </td>
            </tr>
            <tr>
                <td>
                    <image src='/SupController/ViewPDFDocument/<%= Html.Encode(Model.Id) %>' alt="" style="visibility:hidden;" />
                </td>
            </tr>
        </table>
        <iframe src="" name="iframe_a" style="height: 1000px; width: 1350px;border:1px solid;border-color:lightgray;"></iframe>
      
    </div>




No comments:

Post a Comment