开发者

How to get this file prompted to the user?

Hi Im working on a MVC3 Razor project and I have been stuck on this problem for a few开发者_Python百科 hours now...

I'm trying to get a html to pdf converter to serve a document to the user...

What I want is the following..

A page is rendered and displayed. On the bottom of the page there should be a little icon display something like download as pdf. and what that does is where my problem lies..

All the data that I want is dynamically created within a $("#content").html();

So what I have tried is a jquery/ajax function passing $("#content").html(); as a paramater to my function which creates the pdf (works but I have no clue how to prompt the created file to the user?)

Other solution was @(Html.ActionLink()) but I dont know how to pass the data ($("#content").html()) within that link?

And when trying to work with the functionallity to use the converter to go to the url was a dead end cuz it got its own session and got redirected to the loginpage..

Any help would be appriciated!


I am not familiar with JavaScript, but what if you save the PDF in the temp file first by calling you web service method, and then after it completed you can use JavaScript to navigate to the URL where generated PDF will be returned as content.


Since the XmlHTTPRequest Object cannot handle datatypes other than html, text, json, jsonp and xml you will need to redirect to the pdf location.

I'm not sure what exactly you're doing in your Ajax Request, but once that is completed you can just redirect the window(Form-Action) to the location of the created PDF. This wouldn't actually redirect the browser but only prompt for saving the file.


Why just create a function that returns the created PDF (during ajax request) as File result and then set the window's location to point to this action once the ajax request is completed successfully?

Edit: That means you are not saving the PDF anywhere. So the workaround, is to either use this jquery download plugin or append an iframe dynamically and then post the data through it. Hope this helps.


Figured out a workaround, what I did was write an extension to my HtmlHelper and use that to render my control into a html string instead of a view. Therefor I could use a actionlink to say render this page and get all the html data that way.

http://msug.vn.ua/Posts/Details/3301

Thanks for help tho!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜