ckeditor.js:219 Uncaught TypeError: Cannot set property 'dir' of undefined
ckeditor.js:219 Uncaught TypeError: Cannot set property 'dir' of undefined
我在我的项目中安装了 logical Uploader for ckeditor,并且安装没有问题。我有以下控制器:
public class Default1Controller : Controller
{
//
// GET: /Default1/
Context _db = new Context();
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(content model)
{
_db.tbl_Content.Add(model);
_db.SaveChanges();
return View();
}
}
和我的内容模型:
public class content
{
[Key]
public int id { get;set; }
public string text { get; set; }
}
我的强类型索引视图:
@model ckeditor.Models.content
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>content</legend>
<div class="editor-label">
@Html.LabelFor(model => model.text)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.text)
@Html.ValidationMessageFor(model => model.text)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script src="~/Scripts/ckeditor/ckeditor.js"></script>
<script src="~/Scripts/ckeditor/adapters/jquery.js"></script>
<script>
$(function () {
$('#text').ckeditor();
});
</script>
}
但我的 @html.TextAreaFor()
上没有 ckeditor
我应该怎么办?
尝试设置 CKEDITOR_BASEPATH
变量:
<script>
var CKEDITOR_BASEPATH = '/Scripts/ckeditor/';
</script>
参见文档 here。
对于其他有此问题的人(因为它在此时的最新版本中仍然存在),如果您在解决方案中自行托管了 CKEditor 脚本(例如对于经典 ASP.NET 应用程序)并且您的 CKEditor 文件夹中没有插件的所有本地化文件,这可能会导致此问题发生。
例如,我们的 /CKEditor/lang/
文件夹中只有 en.js
文件,当用户同时使用英语和丹麦语作为他的浏览器语言时,就会出现错误。 CKEditor 尝试自动将编辑器的语言设置为丹麦语,并尝试加载不存在的 /CKEditor/lang/da.js
文件(导致 404 错误)。如此处的原始问题所示,浏览器控制台在尝试加载 /lang/fa.js
语言文件时显示 404 错误,但无济于事。将以下内容添加到 config.js 文件为我们解决了问题:
config.language = 'en';
setting config.language 确保编辑器的语言设置为英语,而不是自动检测。
我在我的项目中安装了 logical Uploader for ckeditor,并且安装没有问题。我有以下控制器:
public class Default1Controller : Controller
{
//
// GET: /Default1/
Context _db = new Context();
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(content model)
{
_db.tbl_Content.Add(model);
_db.SaveChanges();
return View();
}
}
和我的内容模型:
public class content
{
[Key]
public int id { get;set; }
public string text { get; set; }
}
我的强类型索引视图:
@model ckeditor.Models.content
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>content</legend>
<div class="editor-label">
@Html.LabelFor(model => model.text)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.text)
@Html.ValidationMessageFor(model => model.text)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script src="~/Scripts/ckeditor/ckeditor.js"></script>
<script src="~/Scripts/ckeditor/adapters/jquery.js"></script>
<script>
$(function () {
$('#text').ckeditor();
});
</script>
}
但我的 @html.TextAreaFor()
上没有 ckeditor
我应该怎么办?
尝试设置 CKEDITOR_BASEPATH
变量:
<script>
var CKEDITOR_BASEPATH = '/Scripts/ckeditor/';
</script>
参见文档 here。
对于其他有此问题的人(因为它在此时的最新版本中仍然存在),如果您在解决方案中自行托管了 CKEditor 脚本(例如对于经典 ASP.NET 应用程序)并且您的 CKEditor 文件夹中没有插件的所有本地化文件,这可能会导致此问题发生。
例如,我们的 /CKEditor/lang/
文件夹中只有 en.js
文件,当用户同时使用英语和丹麦语作为他的浏览器语言时,就会出现错误。 CKEditor 尝试自动将编辑器的语言设置为丹麦语,并尝试加载不存在的 /CKEditor/lang/da.js
文件(导致 404 错误)。如此处的原始问题所示,浏览器控制台在尝试加载 /lang/fa.js
语言文件时显示 404 错误,但无济于事。将以下内容添加到 config.js 文件为我们解决了问题:
config.language = 'en';
setting config.language 确保编辑器的语言设置为英语,而不是自动检测。