我試圖在我的web應用程序中使用雅虎富文本編輯器。我對網絡編程很陌生,所以這可能是一個愚蠢的問題。如何發佈JavaScript變量到ASP.net MVC模型?
我正在使用名爲「blogpost」的自定義模型。它包含以下屬性:
標題 身體 dateCreated會 作者
我想使用的自定義編輯器只對「身體」屬性。當我點擊提交時,它將從簡單的文本框構建模型的其他屬性。我已經將下面的代碼放在我的輸入表單代碼中。
<div class="yui-skin-sam">
<textarea name= "msgpost" id="msgpost" cols="50" rows="10">
</textarea>
<script>
var myEditor = new YAHOO.widget.Editor('msgpost', {
height: '300px',
width: '522px',
dompath: true, //Turns on the bar at the bottom
animate: true //Animates the opening, closing and moving of Editor windows
});
myEditor.render();
YAHOO.util.Event.on('Create', 'click', function() {
myEditor.saveHTML();
var body = myEditor.get('element').value;
});
</script>
@ViewData.Add("Body",//how do I add the javascript variable "body" ?)
</div>
如何「發佈」javascript變量「body」,以便MVC模型構建器能夠識別它?
採取了第二個途徑。謝謝! – ZeroDivide 2011-05-31 05:58:19