开发者

Should I write from Controller, Code Behind, or Helper in MVC?

I've seen all the questions and answers around not having code-behind for a view, however I have a case where I need complex logic to generate the presentation (view) layer. I have to output a PDF file based on data obtained from db. Where is the best place to generate this PDF and write to the response stream? Doing response.write from the controller feels very wrong to me, but I开发者_开发技巧 would like responses to this, and to using a code-behind file for the view to generate the PDF. I suppose I could encapsulate the data in a viewmodel class and pass that to a Helper method to generate the output as well, what would be considered best practice in this case, specifically having a lot of logic around creating the PDF?


I would create a ActionResult class for this and return that from the controller. The ActionResult class is responsible for writing stuff to the output stream.


The better way to do it is by defining an ActionResult specific for outputting pdf files. This way you can reuse the code easily also in other applications

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜