MVC:Ace编辑帖子 [英] MVC: Ace editor post

查看:73
本文介绍了MVC:Ace编辑帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在编写CMS系统,并且使用ACE语法突出显示工具在文本框中突出显示一些HTML.

I'm currently writing a CMS system and I use the ACE syntax highlighter to highlight some HTML in a textbox.

现在,我有一个显示内容的表格:

Now, I have a form in which the contents are showed:

<div id="editor">@Html.TextAreaFor(model => model.Body)</div>

使用以下javacsript激活语法突出显示器:

The syntax highlighter is activated with the following javacsript:

<script>
    var editor = ace.edit("editor");
    editor.setTheme("ace/theme/eclipse");
    editor.renderer.setShowGutter(false);
    editor.getSession().setMode("ace/mode/html");
</script>

但是在我的控制器中,我没有得到高光文本区域的内容,这是正常的,因为语法荧光笔正在生成复杂的HTML.

But in my controller, I'm not getting the contents of the hihglighted textarea, which is normal because of the complex HTML that the syntax highlighter is generating.

有人对如何解决这个问题有想法吗?

Anyone who has an idea on how to solve this?

推荐答案

在将数据发布到服务器之前,必须将其分配给隐藏字段或文本区域.此问题已在此处的StackOverflow 上得到了回答

Before posting the data to the server, you have to assign it to a hidden field or back to the text area. This question was already answered on StackOverflow here

@Jan Jongboom使用以下代码在发布之前分配ACE编辑器的值:

@Jan Jongboom uses the following code to assign the value of the ACE editor before the post:

<%=Html.HiddenFor(m=>m.Editor, new { @id = "hidden_editor" }) %>

<!-- this is jQuery, but you can use any JS framework for this -->
<script>
    $("form").submit(function () {
        $("#hidden_editor").val(editor.getSession().getValue());
    });
</script>

这是MVC 2标记,但可以很容易地应用于Razor.

This is MVC 2 markup, but can be easily adopted to Razor.

这篇关于MVC:Ace编辑帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆