开发者

How can I export to a pdf file in asp.net mvc 3

I want to make an application that exports a PDF file whose content comes from the database. This my controller controller:

 public ActionResult DownloadTopic(int Id)
    { 
      开发者_JS百科  var Topic = DB.Topics.singleordefualt(o=>o.id == Id);

        return File(Topic.Body, "application/pdf");
    }

But I get this error "Could not find a part of the path 'C:\Users\katkooot\Desktop\project\Discussion\MvcApplication22\MvcApplication22\Topic\DownloadTopic".


You need to convert the result into PDF. You cannot just take the result that is some .NET class, interface or custom user object and return it as PDF just like that. You should use libraries like iTextSharp to enumerate through your results and return a PDF. Here is a tutorial by Ozzie Perez on how to open a document, write a PDF table and return it to the user Creating a PDF with iTextSharp and ASP.Net MVC 2


You didn't provide enough details, it would greatly help if you would answer what others asked - what is the type of Topic.

But based on this as a wild guess - try to return FileContent instead of File.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜