This is a migrated thread and some comments may be shown as answers.

[Solved] Render without Render

1 Answer 24 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
MacLeod
Top achievements
Rank 1
MacLeod asked on 21 Jul 2011, 02:52 PM
Hi,

Can someone please explain how the following the following is achieved. The Telerik Grid component will generate non-encoded HTML with the following code:

@(Html.Telerik().Grid(Model)
        .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.ProductID))
        .DataBinding(dataBinding => dataBinding.Server()
            .Select("ColumnSettings", "Grid")
            .Update("ColumnSettings_Save", "Grid")
            .Delete("ColumnSettings_Delete", "Grid"))
        .Columns(columns => columns.LoadSettings((IEnumerable<GridColumnSettings>)ViewData["Columns"]))
        .Sortable()
)

Presumably this happens because the method call is wrapped in "@(....)". Whenever I try this with my own components the result is encoded Html. I know that I can use Render() to output an MvcHtmlString and then my Html is not encoded but the Telerik grid seems to achieve it without .Render(). 

Can anyone explain the secret to me?

Thanks in advance.


1 Answer, 1 is accepted

Sort by
0
MacLeod
Top achievements
Rank 1
answered on 21 Jul 2011, 05:28 PM
Hi,

I found the answer. If the component builder implements IHtmlString then Razor will call ToHtmlString() instead of ToString() and it will not be Html encoded.

mn
Tags
General Discussions
Asked by
MacLeod
Top achievements
Rank 1
Answers by
MacLeod
Top achievements
Rank 1
Share this question
or