Render view as string then redirect.

Posted by JohnRudolfLewis on Stack Overflow See other posts from Stack Overflow or by JohnRudolfLewis
Published on 2009-05-16T17:20:00Z Indexed on 2010/03/29 19:03 UTC
Read the original article Hit count: 337

Filed under:

In my ASP.NET MVC application, I would like my controller action to render a view to a string, send an email using that string as the body, then do a redirect.

I've found several articles here on SO and elsewhere on how to render the view to a string. That part was easy.

But when I attempt to perform the redirect, I get an HttpException: Cannot redirect after HTTP headers have been sent. I've tried setting Response.Buffer and Response.BufferOutput to true, I've tried Response.Clear, nothing seems to work.

Is it possible to render a view to a string, then do a redirect?

© Stack Overflow or respective owner

Related posts about asp.net-mvc