MVC4 使用 ckfinder+ckeditor编辑器
配置
ckfinder for asp.net 版本下载地址 http://cksource.com/ckfinder/download
ckeditor下载地址 http://ckeditor.com/download
config.ascx
public override bool CheckAuthentication() { return true; 设置为true }
config.filebrowserBrowseUrl = '/ckfinder/ckfinder.html'; //不要写成"~/ckfinder/..."或者"/ckfinder/..." config.filebrowserImageBrowseUrl = '/ckfinder/ckfinder.html?Type=Images'; config.filebrowserFlashBrowseUrl = '/ckfinder/ckfinder.html?Type=Flash'; config.filebrowserUploadUrl = '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files'; config.filebrowserImageUploadUrl = '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images'; config.filebrowserFlashUploadUrl = '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash'; config.filebrowserWindowWidth = '800'; //“浏览服务器”弹出框的size设置 config.filebrowserWindowHeight = '500'; }
View
引用JS
<script src="../../ckeditor/ckeditor.js"></script> <script src="../../ckfinder/ckfinder.js"></script> <script src="../../Scripts/jquery-1.8.2.js"></script> <div> <textarea name="TextArea1" cols="20" rows="2" class="ckeditor">@ViewBag.content</textarea>//新增 <textarea name="TextArea1" cols="20" rows="2" class="ckeditor">@Model.Content</textarea>//编辑 </div> <p> <input type="submit" value="添加" /> </p>
<script type="text/javascript"> $(function () { var editor = CKEDITOR.replace("TextArea1", { "toolbar": "Basic" }); //显示编辑器 CKEDITOR.replace('TextArea1'); var editor = CKEDITOR.replace('TextArea1'); CKFinder.SetupCKEditor(editor, '/ckfinder/'); }) </script>
Controller
[HttpPost] [ValidateInput(false)] //设置避免出现 检测到有潜在危险的 Request.Form public ActionResult Edit(int id, FormCollection collection) { var content = collection["TextArea1"]; var userinfo = db.userinfo.Find(id); userinfo.img = img; db.SaveChanges();return RedirectToAction("Index"); }