Thursday, July 26, 2012

Problem with Response.Output in Razor

Problem with Resonse.Output in Razor

I have a helper class which writes directly in Response. I am using this helper class in my master page and it write in the position
where Helper class is called.

<% Html.MyHelper() %>

but in Razor

@{ Html.MyHelper() }

its writing the response on the begining of page.

A Razor view is rendered inside-out. Basically it writes content to temporary buffers which get written to the response stream when the top most layout page is reached.

private static void MyHelper(this HtmlHelper html)
{
HtmlTextWriter writer = new HtmlTextWriter(html.ViewContext.HttpContext.Response.Output);
}


to replace using
html.ViewContext.HttpContext.Response
with
html.ViewContext.write

No comments:

Post a Comment