设置MVC操作URL以在网页(.aspx)中的iframe控件中内联显示PDF

问题描述:





我有一个场景,就是在aspx页面的IFrame控件中显示PDF内联。通过将复杂对象的参数发送到动作,将从MVC控制器动作接收PDF内容作为FileContentResult。在我的代码中,我通过使用序列化值的查询字符串对URL进行硬编码来设置iframe的src属性



代码落后:



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








Controller.cs

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







对于上面的场景,我发送的值更大一个并且查询字符串限制是2093个字符,因此值被截断并且控制器获取不正确的值。因为参数返回空值,所以无法通过调用控制器操作中的服务来获取文件内容。







请指导获得预期产量的可能方法。



预付款





问候,



Gopi



我尝试过:






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:

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.

.Post()和


.ajax()方法调用控制器操作,但得到像filecontent的一些原始数据的响应。所以不知道如何将 放入 iframe控制。
.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.