I cannot display the string representation and then redirect, despite this answer from Feb (after version 1.0, I think), which claims that this is possible. I thought I was doing something wrong, and then I read this answer from Haack in July , which claims this is not possible.
If someone works and can help me get him to work, thatβs great (and I will send the code, errors). However, I am now in need of workarounds. There are few, but nothing perfect. Has anyone solved this or had any comments on my ideas?
- This is for email rendering. Although I can send emails outside of the web request (store information in db and receive it later), there are many types of emails, and I do not want to store the template data (user object, several other LINQ objects) in db, so that I can receive it later visualization. I could create a simpler, serializable POCO and save it in db, but why? ... I just need visualized text!
- I can create a new RedirectToAction object that checks if headers have been sent (I canβt figure out how to do it - try / catch?) And, if so, it creates a simple meta-redirected page, javascript redirect, as well as a click link here".
- In my controller, I can remember if I sent an email, and if so, manually do # 2, showing the view.
- I can manually send redirect headers before any potential email rendering. Then, instead of using the MVC framework to redirect the redirect, I just call result.end. It seems simple but really dirty.
- Anything else?
EDIT : I tried the Dan code (very similar to the code from January / February that I already tried), and I still get the same error. The only significant difference that I see is that his example uses a view while I use a partial view. I will try to check this later with a view.
Here is what I have:
controller
public ActionResult Certifications(string email_intro) {
SendEmail ()
public static void SendEmail(ViewModels.Emails.Certifications.Open model, ControllerContext context) { var vd = context.Controller.ViewData; vd["model"] = model; var renderer = new CustomRenderers();
Customrenderers
public class CustomRenderers { public virtual string RenderViewToString3(ControllerContext controllerContext, string viewPath, string masterPath, ViewDataDictionary viewData, TempDataDictionary tempData) {
Error
[HttpException (0x80004005): Cannot redirect after HTTP headers have been sent.] System.Web.HttpResponse.Redirect(String url, Boolean endResponse) +8707691
Thanks James
source share