Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a scenario like to show a PDF inline in IFrame control in aspx page. PDF content will be received from MVC controller action as FileContentResult by sending a parameter of complex object to action. In my code, I set src property of iframe in code behind by hardcoding the URL with a querystring of serialized value

Code behind:

C#
TestPDF obj = new TestPDF
 {
  Employee = new Employee { EmpNo = 10, Name = "Gopi" }
 };

var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
 string jsonString = javaScriptSerializer.Serialize(obj);
 framePdf.Src ="http://localhost:56336/Home/Test?pdfData=" + HttpUtility.UrlEncode(jsonString);





Controller.cs

[HttpGet]
         public ActionResult Test(TestPDF pdfData)
         {
             byte[] bytes = System.IO.File.ReadAllBytes(@"C:\Test.pdf");
             return new FileContentResult(bytes, "application/pdf");
         }



For the above scenario, the value that I am sending is bigger one and the query string limit is 2093 charaters so the value is truncated and controller gets incorrect value. so unable to get the file content by calling the service in controller action due to the parameter returns null value.



Please guide the possible ways to obtain the expected output.

Advance thanks


Regards,

Gopi

What I have tried:

C#
I tried in client side programming using $.Post() and $.ajax() method to call the controller action but getting a response like some raw data of filecontent. so do not know how to put this into iframe control.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900