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 = '
}
});
}
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 =)
4 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sachin SinghPosted Dec 13, 2020, 8:44 PM
Mageshwaran RPosted Dec 13, 2020, 8:19 PM
Athirah ZainPosted Dec 13, 2020, 8:02 PM
Sachin SinghPosted Dec 10, 2020, 2:45 AM