0

I need to send a big block of HTML in a Json object like this:

                JsonResult jsn =  Json(new Dictionary<string, object> { { "success", true }, 
            { "lastPID", posts[0].ID }, 
            { "content", "" } });
            return jsn;

For some reason I get this error when I put that html block into the content variable: Server cannot set content type after HTTP headers have been sent.

This doesn't happen if I return some random non-html content.

Is there any encoding that I need to do before I can send my big block of html?

What about the client end? How do I get back the data.

Cyril Gupta
  • 13,142
  • 11
  • 62
  • 84

2 Answers2

2

Looks like this is your problem (and solution)

Community
  • 1
  • 1
David Hedlund
  • 125,403
  • 30
  • 199
  • 217
1

If you need to send HTML, why not just send HTML rather than JSON?

Ian Oxley
  • 10,756
  • 6
  • 40
  • 48
  • Because I also need to send some other data 'lastPID' in the same result. It's very important that I send the lastPId. – Cyril Gupta Jan 07 '10 at 11:30
  • One way is to have a javascript function inside the send html that sets the id. If you render the hmtl this function can get called (ie by $(document).ready) – Mathias F Jan 07 '10 at 13:13