Athirah Zain

Athirah Zain

  • NA
  • 48
  • 447

Display PDF (path location is from server's column)

Dec 10 2020 1:54 AM
I have a problem to display my PDF file in my web page.
I am very new to programming, maybe my method is wrong that is why it can't be displayed. 
I am using MVC framework. 
 
My controller's code; 
 
public ActionResult ViewPDF(string SelectedStandard)
{
var smlPortalDb = new SMLPORTALEntities();
try
{
var pdfLocation = smlPortalDb.SML_Std_Procedures
.Where(a => a.StandardOperation == SelectedStandard)
.Select(a => a.FilePath)
.FirstOrDefault();
var data = new { pdfLocation, Msg = "OK" };
return Json(data, JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
 
 
Here is my code inside .js file (in Script): 
 
self.SelectedStandard = ko.observable();
self.Search = function () {
if (initialReload)
return;
var SelectedStandard = self.SelectedStandard();
$.ajax({
url: '/General/ViewPDF',
cache: false,
type: 'GET',
data: { SelectedStandard },
success: function (dataServer) {
$("#pdfsource").innerHtml = '<embed style="width:1050px; height: 500px" src="' + dataServer.pdfLocation + '">';
}
});
}
 
 
And here is my codes for .html files (in View); 
 
data-bind="click:Search" id="pdfsource" href="~/pdf/MYFILE R0XXXX-XXX PDF TEST.pdf" target="_blank">
Search
 
 
I want my PDF to be displayed upon clicking [Search] button. 
Can anyone who is expert in this help me please? 
Thank you so much in advanced =) 
 
 

Answers (4)