Integrate CKEditor and CKFinder

Bài viết dưới đây hướng dẫn cách tích hợp CKEditor và CKFinder trong ASP.NET MVC. Các bước thực hiện:

  1. Download CKEditor ở địa chỉ CKEditor 4.5.11
  2. Download CKFinder ở địa chỉ CKFinder
  3. Giải nén và copy 2 thư mục CKEditor và CKFinder vào trong thư mục gốc của website, ví dụ cấu trúc ứng dụng web là CMS thì 2 thư mục CKEditor và CKFinder sẽ là (nhớ xóa hết các file source của ckedit và ckfinder):
    • CMS\ckeditor
    • CMS\ckfinder
  4. Chèn scripts vào View cần tạo CKeditor và CKFinder

@section scripts
{
http://~/ckeditor/ckeditor.js
http://~/ckfinder/ckfinder.js
}

5. Chèn CKeditor vào View như sau

@Html.LabelFor(model => model.Content, htmlAttributes: new { @class = “control-label col-md-2” })

@Html.TextAreaFor(model => model.Content, new { htmlAttributes = new { @class = “form-control” } })
@Html.ValidationMessageFor(model => model.Content, “”, new { @class = “text-danger” })

</div>

6. Bổ sung script để tạo CKeditor và tích hợp CKFinder

var editor = CKEDITOR.replace(‘Content’); //Tạo CKEditor
CKFinder.setupCKEditor(editor, ‘/ckfinder/’);//Tích hợp CKFinder

Html.Partial vs RenderPartial vs Action

Bài dưới đây chỉ ra sự khác nhau giữa các cách dùng PartialView trong ASP.NET MVC

Render Partial View:

Có nhiều cách để render Partial View, tuy nhiên mỗi cách có mục đích sử dụng riêng: Partial() or RenderPartial() or RenderAction():

Html.Partial()

@Html.Partial() render ra một partial view, khi gọi @Html.Partial() sẽ trả về một chuỗi và chèn vào trang (ở vị trí gọi @Html.Partial()) trước khi trang được hiển thị ra trình duyệt.

@Html.RenderPartial()

@RenderPartial với mục đích tương tự như Partial() là render ra một Partial View, điểm khác biệt giữa RenderPartial và Partial là nó trả về void, kết quả trả về ghi trực tiếp ra Response stream.

Html.RenderAction()/Action():

@RenderAction() gọi action của controller và trả về kết quả là một partial view.