asp.net-mvc是否可以获取ViewData并将其粘贴到javascript函数中

leo*_*ora 1 asp.net-mvc

我有以下javascript从某个地方获取HTML并将其粘贴在textarea中以获取tinymce.

我的问题是如何在asp.net-mvc中我可以获取HTML Here并将其粘贴在javascript中?

我把它放在ViewData中吗?

function ajaxLoad() {
        var ed = tinyMCE.get('elm1');
        // Do you ajax call here, window.setTimeout fakes ajax call
        ed.setProgressState(1); // Show progress
        window.setTimeout(function() {
            ed.setProgressState(0); // Hide progress
            ed.setContent('HTML Here');
        }, 500);
    }
Run Code Online (Sandbox Code Playgroud)

我想在下面有这样的东西,但它似乎不起作用:

function ajaxLoad() {
        var ed = tinyMCE.get('elm1');
        // Do you ajax call here, window.setTimeout fakes ajax call
        ed.setProgressState(1); // Show progress
        window.setTimeout(function() {
            ed.setProgressState(0); // Hide progress
            ed.setContent(<% ViewData["test"] %>);
        }, 500);
    }
Run Code Online (Sandbox Code Playgroud)

nki*_*kes 5

我认为ajax调用可能最适合你,但也要确保你正在尝试<%= ViewData["test"],注意第一个百分号之后的"=".你给出的例子不会像你那样发出ViewData字段的值(也许这只是一个错字?).