How to accept html content as a parameter to a helper function in MVC+Razor?

Viewed 1753

I notice that some Razor functions take html content as parameters, eg.:

@section Scripts  {
    <script type="text/javascript">
        $(function() {
            alert("aha");
        });
    </script>
}

This doesn't render the html content immediately rather Razor's Section() system stores it for later rendering.

I would like to write my own helper function which accepts html content in the same way, eg.:

@Html.MyCoolFunction {
    <div><stuff><blah>...
    dafsdfsa
    </blah></stuff></div>
}

I don't know what syntax would work, but presumably MyCoolFunction would accept an MvcHtmlString as a parameter and I can do what I want with it.

Is this possible?

1 Answers
Related