BlockRenderer method broken in RC1?

Last post 02-01-2009 3:58 PM by Nik Coughlin. 9 replies.

Sort Posts:

  • BlockRenderer method broken in RC1?

    01-27-2009, 7:50 PM
    • Member
      point Member
    • brs
    • Member since 06-27-2008, 1:10 AM
    • Posts 18

    Hello, 

    In my app I need to be able to update several parts of the page with a single ajax request.

    I have been using the BlockRenderer method for rendering several partial views. I then stick the rendered html into a JSON object for the javascript to insert into the page.

    It appears RC1 breaks the BlockRenderer method. After rendering a partial view, the response stream must be flushed before you can retrieve the contents of the CapturingResponseFilter. It looks like Render() now resets the content type-- but since the response is flushed the first time you render a view, the headers are sent, and when the second view is rendered, you get an exception when it tries to reset the content type.

    Is this related to the comment in the release notes about RenderPartial no longer resetting the content type? How can I work around this? Thanks in advance.

  • Re: BlockRenderer method broken in RC1?

    01-27-2009, 9:43 PM
    • Member
      30 point Member
    • Nik Coughlin
    • Member since 09-24-2008, 1:46 AM
    • Auckland, New Zealand
    • Posts 15

    I was going to transition to RC1 today too, glad I didn't. 

    I'm doing something vaguely similar, using a BlockRenderer so that I can do RenderPartialToString

    We need to be able to render partials to strings!  There are just too many things that it's useful for. 

    Either that or stop using the webform view.  God knows I'm not terribly fond of it... but I like intellisense too much to change my view engine.

  • Re: BlockRenderer method broken in RC1?

    01-28-2009, 12:17 PM
    • Member
      point Member
    • brs
    • Member since 06-27-2008, 1:10 AM
    • Posts 18

    I agree, and it seems like a common enough request/complaint. I have been hoping that there would be a good way to do this before the final release, but that's looking less & less likely. It only seems to be getting more difficult with each new release...

    I have also considered switching to a new view engine, but it would require rewriting quite a bit of code, which I would obviously like to avoid.

  • Re: BlockRenderer method broken in RC1?

    01-28-2009, 12:32 PM
    • Contributor
      5,773 point Contributor
    • Haacked
    • Member since 09-17-2003, 2:43 PM
    • Posts 388
    • AspNetTeam

    The reason we reset the content type is that if you set the content type in the action method, when you render the view, the view would change the content type. This is due to the Page's ProcessRequest method which sets the content type. Hopefully we can look at making changes to the core Page class in .NET 4, but we'll see. Sorry for the annoyance.

    Phil Haack (http://haacked.com/)
    Senior Program Manager, Microsoft

    What wouldn’t you do for a Klondike bar?
  • Re: BlockRenderer method broken in RC1?

    01-28-2009, 12:43 PM
    • Member
      point Member
    • brs
    • Member since 06-27-2008, 1:10 AM
    • Posts 18
    Thanks for the explanation Phil. Can you recommend any alternatives for capturing the rendered HTML from a partial view? If not, is there any other way to update several different components of the page in a single request? Unfortunately my app is pretty dependent on this.
  • Re: BlockRenderer method broken in RC1?

    01-28-2009, 3:47 PM
  • Re: BlockRenderer method broken in RC1?

    01-28-2009, 4:17 PM
    • Member
      point Member
    • brs
    • Member since 06-27-2008, 1:10 AM
    • Posts 18

     Thanks, but the methods there are very similar to the block renderer, and have the same problem...

  • Re: BlockRenderer method broken in RC1?

    01-29-2009, 11:56 AM
    • Member
      10 point Member
    • Herne
    • Member since 05-20-2008, 3:02 PM
    • Posts 12

    Does anyone have any alternative ideas?

    (Or a pointer to an idea :) )

  • Re: BlockRenderer method broken in RC1?

    01-30-2009, 4:31 AM
    • Member
      10 point Member
    • Herne
    • Member since 05-20-2008, 3:02 PM
    • Posts 12

    I've changed the last line of PartialRequest.Invoke to

    SimpleWorkerRequest request = new SimpleWorkerRequest("dummy.html", null, new StringWriter(CultureInfo.CurrentCulture));
    handler.ProcessRequest(new HttpContext(request));
     
    and everything seems to be working again. Thoughts?

    Edit: Just to clarify, I'm using BlockRenderer this way.
  • Re: BlockRenderer method broken in RC1?

    02-01-2009, 3:58 PM
    • Member
      30 point Member
    • Nik Coughlin
    • Member since 09-24-2008, 1:46 AM
    • Auckland, New Zealand
    • Posts 15

    Thanks for posting that Herne, that's extremely reassuring!

Page 1 of 1 (10 items)