2016-12-30 187 views
1

我试图在ASP.NET MVC 5中使用TinyMCE,但是,它似乎不起作用。 textarea出现了,但它是一个普通的textarea,并没有丰富TinyMCE的功能。ASP.NET MVC 5中的TinyMCE Razor

查看\ Shared_Layout.cshtml

<link rel="stylesheet" type="text/css" href="~/Content/jquery.datetimepicker.css"/> 
<script src="~/Content/jquery.js"></script> 
<script src="~/Content/build/jquery.datetimepicker.full.min.js"></script> 
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script> 
<script type="text/javascript"> 
    tinyMCE.init({ 
     mode: "specific_textareas", 
     editor_selector: "editorHtml", 
    }); 
</script> 

查看\ MyView的\ Create.cshtml

@Html.TextAreaFor(model => model.Corpo, new { htmlAttributes = new { @class = "form-control editorHtml" } }) 

任何提示吗?

这样

<textarea cols="20" htmlattributes="{ class = form-control editorHtml }" 
             id="Corpo" name="Corpo" rows="2"></textarea> 

+0

您是否检查了JavaScript控制台以查看是否有任何错误? – mason

回答

2

当前视图代码产生输出这不看起来是正确的。它没有添加你想要的CSS类,而是添加了一个名为htmlAttributes的新属性!为什么?因为你以不正确的方式使用了辅助方法!

因此,修复您的帮助器方法调用中的错误代码。第二个参数采用单个匿名对象。

@Html.TextAreaFor(model => model.Corpo, new { @class = "form-control editorHtml" }) 

这应该为文本区域(检查页面的查看源代码)生成正确的html代码。

现在您的现有代码来初始化富文本编辑器将工作。或者,您也可以使用Id选择器。

<script> 

    tinymce.init({ 
     selector: "#Corpo" 
    }); 

</script> 
+0

正确的Shyju。我不应该使用'htmlAttributes'。 – Lernas