0

I have a HtmlHelper that renders a grid as a table, in MVC2 I would call it from the view using the following syntax...

<%=
    Html.MyLibrary().Grid<MyGridItem>()
        .Name("MyGrid")
        .Width("100%")
        .Render()
%>

Notice it uses templates. In MVC3 with Razor it won't compile, seemingly because the left angle bracket '<' is being confused for html. To get around this I can enclose it in curly braces...

@{Html.MyLibrary().Grid<MyGridItem>()
        .Name("MyGrid")
        .Width("100%")
        .Render();}

but now the problem is that the string returned from .Render() doesn't get put in the output stream!

Any help solving this would be much appreciated.

MarkB
  • 174
  • 14

1 Answers1

0

You should use Html.Raw() Method.

@Html.Raw(Html.MyLibrary().Grid<MyGridItem>()
        .Name("MyGrid")
        .Width("100%")
        .Render())

The @{...} server side block does not get rendered because it's simple server side code. Same if you wrote

@{ "renderedstring".ToString(); }
archil
  • 39,013
  • 7
  • 65
  • 82