第一步 安装CKEditor 4
Visual Studio 中选择菜单 工具(&T) - NuGet包管理器(&N) - 管理解决方案的NuGet程序包(&N),在搜索框中输入 CKEditor,找到对应版本进行安装。
第二步 修改 App_StartBundleConfig.cs
在合适位置加入如下代码:
bundles.Add(new ScriptBundle("~/bundles/ckeditor").Include("~/Scripts/CKEditor/ckeditor.js")); bundles.Add(new ScriptBundle("~/bundles/ckeditor_config").Include("~/Scripts/CKEditor/config.js"));
第三步 修改视图:
在合适位置加入如下代码:
@Scripts.Render("~/bundles/ckeditor") @Scripts.Render("~/bundles/ckeditor_config")
修改文本编辑框的class属性:
修改前:@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
修改后:@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "ckeditor" } })
第四步 修改控制器
将属性修饰[ValidateAntiForgeryToken]修改为[ValidateInput(false)]
开始使用吧!