Documentation

Page data scripts

Cassette's AddPageData allows a page to make server-side data available to the client-side JavaScript.

@{
    Bundles.AddPageData("pageData", new { message = "Hello" });
}

This will add a <script> block to the page that defines a global object containing the data you provided. For example:

<script type="text/javascript">
    (function (w) {
        var d = w['pageData'] || (w['pageData'] = {});
        d.message = "Hello";
    } (window));
</script>