gmail user
gmail user

Reputation: 2783

reuse of mvc view

I'm working on the MVC app where I've to generate the report in the form of HTML page. If the user click the print icon, I've to show the HTML page to user. If the user click on email icon, I've to send email with same HTML page attachment. I'm trying to find a way where I can use the same code to generate the HTML in both cases of email and print. Please provide your suggestions.

Upvotes: 0

Views: 489

Answers (2)

mare
mare

Reputation: 13083

What you really want and did not know how to formulate is Render view to string. Then you can do whatever you want with the contents of that string.

Start here Render a view as a string

but this subject continues in many other questions too (or you can Google it) and you will discover much more information.

Upvotes: 1

Alec
Alec

Reputation: 9078

Your Controller has to decide what to do.

  1. User clicked print. Controller action: collect data, prepare the View, display as HTML page
  2. User clicked email. Controller action: collect data, prepare the View, call on an email-function and use the output of the HTML page as an attachment.

Upvotes: 0

Related Questions