CKEditor and ASP.Net MVC 3 RequiredAttribute

前端 未结 7 585
情深已故
情深已故 2020-12-08 15:56

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 edi

相关标签:
7条回答
  • 2020-12-08 16:26

    For me this code does the trick, it could probably be optimized a bit but it works:

    $('#newsForm').submit(function (event) {
         var editor = $('#Body').ckeditorGet();
         editor.updateElement();
         $(this).validate().form();
    });
    

    Because I don't know in which order the eventhandlers for submit runs I make sure to both update the value and refresh the validation result.

    EDIT: Updated solution

    <script type="text/javascript">
        //<![CDATA[
        $(document).ready(function () {
            $('#Body').ckeditor();
            $('#newsForm').bind('submit', onFirstSubmit);
        });
    
        function onFirstSubmit(event) {
            var editor = $('#Body').ckeditorGet();
            editor.updateElement();
            $(this).validate().form();
            $(this).unbind('submit', onFirstSubmit).submit();
        }
    
        //]]>
    </script>
    
    0 讨论(0)
提交回复
热议问题