Gopinath

Gopinath

  • NA
  • 11
  • 8.9k

Set MVC action url to show PDF inline in IFrame control(aspx

Dec 2 2016 1:42 AM

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:
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.  
 
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.   
 
Please guide the possible ways to obtain the expected output.   Advance thanks 
 
 
Regards,Gopi
 

Answers (1)