我想在控制器上调用一个动作.让控制器从模型中获取数据.然后该视图将运行并生成PDF.我找到的唯一例子是Lou的一篇文章http://whereslou.com/2009/04/12/returning-pdfs-from-an-aspnet-mvc-action.他的代码非常优雅.该视图使用ITextSharp生成PDF.唯一的缺点是他的例子使用了Spark View引擎.有没有办法用标准的Microsoft视图引擎做类似的事情?
以下代码有效,但我想知道MemoryStream
创建是否正确关闭.应该如何执行或FileStreamResult
为我处理它?
public FileStreamResult DownloadBudgetedRoleOpportunities(
Guid projectGuid,
IEnumerable<Guid> guidRequiredRoles)
{
var rolebroker = new ProjectRoleBudgetBroker();
var memstream = rolebroker.CreateBudgetedRoleOpportunies(
projectGuid,
guidRequiredRoles);
var fsr = new FileStreamResult ( memstream, "application/csv" )
{
FileDownloadName = "RoleOpportunities.csv"
};
// memstream.Close(); throws exception
return fsr;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用iTextSharp生成pdf.我可以从PDF字节[]中保存PDF文件.
byte[] outputPDF = cnt.CreateBreakPDF();
File.WriteAllBytes(pdfOutPutPath, outputPDF);
Run Code Online (Sandbox Code Playgroud)
将输出显示byte[]
到网页的最佳方法是什么?
我想在页面中的div中显示PDF.不是PDF作为完整的回复.
我见过MVC的答案,但我正在使用ASP.NET Web Application.
有没有比使用HTTP处理程序更好的方法呢?我不想发送创建PDF作为查询字符串的所有细节.
从视图中的数据生成html页面的最佳方法是什么?我有一个包含所有表格等的html模板.不想使用像JqueryTemplate这样的任何模板.
嗨,我有一个大问题.我有一个来自Wcf服务的byte [] receveid.字节数组表示pdf文件.在Controller中,我想这样做:
PDFDto pdfDTO = new PDFDTO();
pdfDTO.pdfInBytes = pdfInBytes; //the byte array representing pdf
return PartialView("PopupPDF,pdfDTO);
Run Code Online (Sandbox Code Playgroud)
在视图中我想这样做:
<object data="@Model.pdfInBytes" width="900" height="600" type="application/pdf"> </object>
Run Code Online (Sandbox Code Playgroud)
但似乎没有问题.我在互联网上搜索过,有很多关于这个问题的帖子,但没有人能完全匹配我的情况.你有什么想法吗?非常感谢!
pdf ×4
asp.net-mvc ×2
c# ×2
razor ×2
.net ×1
asp.net ×1
html ×1
html5 ×1
itextsharp ×1
memorystream ×1
mime ×1