Asp.net-Mvc

CKEditor 和 ASP.Net MVC 3 必需屬性

  • December 20, 2010

我已將 CKEditor 3(以前的 FCKEditor)集成到我的 asp.net MVC(具體來說是 v3)應用程序中。我的模型中有一個RequiredAttribute,用於需要編輯器的欄位,但客戶端驗證不能與CKEditor 一起正常工作。當我嘗試送出並將數據輸入 CKEditor 時,所需的驗證看不到數據。如果我再次嘗試重新送出,那麼它可以工作。我在網上看了一圈,找不到解決辦法。我也在使用 Jquery 並使用 Jquery 適配器

<http://docs.cksource.com/CKEditor_3.x/Developers_Guide/jQuery_Adapter>

如果有人正在尋找更通用的方法來執行此操作,您可以添加以下 javascript:

   $(document).ready(function () {
   if ($('.text-editor')) {
       $('.text-editor').ckeditor();
       $('input[type=submit]').bind('click', function() {
           $('.text-editor').ckeditorGet().updateElement();
       });
   }
   });

並在 textarea 上使用 .text-editor css 類,它工作得很好。

@Html.TextAreaFor(model =&gt; model.Description, new { @class = "text-editor" })

我發現這個解決方案比另一個更容易,希望它可以幫助!

引用自:https://stackoverflow.com/questions/4491316