简体   繁体   English

MVC5如何将TinyMCE值绑定到模型

[英]MVC5 how to bind TinyMCE value to model

I tried to bind TinyMCE into my model, but it always return null on postback. 我试图将TinyMCE绑定到我的模型中,但它在回发时始终返回null。 My Code: 我的代码:

View : 查看:

@Html.TextAreaFor(Function(m) m.LangValue)

<script>
    $(document).ready(function () {
        tinymce.init({selector: 'textarea'});
    })
</script>

Model : 型号:

<Required(ErrorMessage:="Required")> _
<Display(Name:="LangValue")> _
<StringLength(8000, ErrorMessage:="Maximum 8000 characters")> _
<AllowHtml()> _
Public Property LangValue As String
    Get
        Return _langValue
    End Get
    Set(value As String)
        _langValue = value
    End Set
End Property

It is working fine if I remove the tinymce script so I checked the HTML and it seems TinyMCE hide the textarea with display: none and replace it with their own UI. 如果我删除tinymce脚本,则工作正常,因此我检查了HTML,似乎TinyMCE用显示隐藏了文本区域:将其隐藏,并用自己的UI替换它。 Is it possible to replace the textarea value with TinyMCE editor value on postback? 回发时可以用TinyMCE编辑器值替换textarea值吗?

Any help will be appreciated. 任何帮助将不胜感激。 Sorry for bad english. 对不起,英语不好。

如果要强制TinyMCE填充隐藏字段,可以在提交之前使用以下功能:

tinyMCE.triggerSave();

So, I fixed it by moving the script 因此,我通过移动脚本来修复它

$(document).ready(function () {
        tinymce.init({selector: 'textarea'});
    })

from inside EditorTemplates to my Layout. 从EditorTemplates内部到我的版式。

I don't know why it doesn't work if I put it inside EditorTemplates because my Layout doesn't have anything after @RenderBody, maybe someone could enlighten me. 我不知道如果将其放在EditorTemplates中为什么不起作用,因为@RenderBody之后的布局没有任何内容,也许有人可以启发我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM