1

This is probably a quick fix, but I am writing to a HtmlTextWriter in my HtmlHelper and no matter what I try it is encoding the HTML so the output shows the markup.

Helper:

protected override void WriteHtml(System.Web.UI.HtmlTextWriter writer)
        {
            writer.WriteFullBeginTag("div");
            writer.WriteEndTag("div");

            base.WriteHtml(writer);
        }

and it will out put this to the page: <div></div>

EDIT

I am calling it in the view like this:

@Html.SAIF().Toolbar().Items(items => {
    items.Add().Action("Action");
    ... ...
})

Edit #2

OK, let's see if I can explain this a little better.

If I use ViewContext.Writer to write my helper to the stream, when using a syntax like this:

@Html.MyHelper

It outputs encoded HTML (e.g.) <div>Test Div</div> = Not correct

If I use a syntax like this:

@{Html.MyHelper.Render();}

It renders correctly, meaning that it actually inserts the div into the DOM instead of displaying it as a string.

Make sense?

Sam
  • 15,336
  • 25
  • 85
  • 148
  • 2
    Have you looked at `@Htmll.Raw()` ? `Raw()` basically creates a `HtmlString` which Razor doesn't escape. – Jamie Dixon Apr 23 '12 at 17:29
  • How does your helper method look like? How are you calling it in the view? You haven't shown enough details in your question. – Darin Dimitrov Apr 23 '12 at 17:30
  • @DarinDimitrov - I have updated my post with the code in the view. – Sam Apr 23 '12 at 17:32
  • Details still missing. How does the helper look like? What's `SAIF`? What's `Toolbar`? What's `Items`? – Darin Dimitrov Apr 23 '12 at 17:34
  • @DarinDimitrov - I am using a framework for View Components I have developed that allow for Fluent configuration of the Html Helpers. Basically I have a static class that provides the `SAIF` Component Factory for the `HtmlHelper`. Then that `ComponentFactory` send back different types of Builders for different view components. – Sam Apr 23 '12 at 17:36
  • I don't really see how we can help without more details or an example that would allow us to reproduce the problem. – Darin Dimitrov Apr 23 '12 at 18:57
  • @DarinDimitrov - Please see my second edit above. – Sam Apr 23 '12 at 19:14

0 Answers0