Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor and ASP.Net MVC 3 RequiredAttribute

Tags:

I've integrated CKEditor 3 (formerly FCKEditor) into my asp.net MVC (v3 to be specific) application. I have a RequiredAttribute in my model for the field that needs the editor but the client side validation doesn't work correctly with CKEditor. When I try to submit and I've entered data into CKEditor the required validation doesn't see the data. If I try resubmitting again, then it works. I've looked around online and can't find a solution. I am also using Jquery and using the Jquery adapter

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

like image 306
B Z Avatar asked Dec 20 '10 15:12

B Z


People also ask

What is CKEditor in asp net?

Last Updated: June 6, 2021. Sometimes you need to provide a feature to add HTML contents in a database table's column. For creating this feature you can use CKEditor which is a free HTML Text Editor. It's integration is fairly simple and this tutorial will teach how to use CKEditor in your ASP.NET Web Forms website.


Video Answer


1 Answers

If someone is looking for a more generic way to do this you can add this javascript :

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

And use .text-editor css class on a textarea and it works just fine.

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

I find this solution eazyer than the other one, hope it can helps!

like image 107
VinnyG Avatar answered Sep 19 '22 18:09

VinnyG