Description:
in this example we explain that how to Display PDF File embedded
in Razor View in MVC or how to Show PDF file in View in Asp.Net MVC Razor.
Here we explain that how to show (Display) the PDF contents in
View in MVC or pdf Viewer in MVC to Show the pdf contents in View.or Display
PDF within web browser using MVC.How to open a pdf file in the view page of
mvc.
So here we demonstrate how to display (view) PDF files within
browser without downloading them in MVC Razor View.
public class EmployeeController : Controller
{
// GET: Employee
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult DisplayorViewPDF()
{
string embed = "<object data=\"{0}\"
type=\"application/pdf\" width=\"500px\"
height=\"300px\">";
embed += "If you are
unable to view file, you can download from <a href = \"{0}\">here</a>";
embed += " or download
<a target = \"_blank\" href =
\"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to
view the file.";
embed += "</object>";
TempData["Embed"] = string.Format(embed, VirtualPathUtility.ToAbsolute("~/Files/Test.pdf"));
return RedirectToAction("Index");
}
}
View:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<title>Index</title>
<style type="text/css">
body {
font-family: Arial;
font-size: 10pt;
}
</style>
</head>
<body>
@using (Html.BeginForm("DisplayorViewPDF", "Employee", FormMethod.Post))
{
<a href="javascript:;" onclick="document.forms[0].submit();">View PDF</a>
<hr/>
@Html.Raw(TempData["Embed"])
}
</body>
</html>
0 comments:
Post a Comment