Asp.net mvc Can';t验证MVC4中的TinyMCE 4控件

Asp.net mvc Can';t验证MVC4中的TinyMCE 4控件,asp.net-mvc,validation,asp.net-mvc-4,unobtrusive-validation,tinymce-4,Asp.net Mvc,Validation,Asp.net Mvc 4,Unobtrusive Validation,Tinymce 4,我正在使用MVC4和knockoutjs(带有映射插件)以及tinymce的绑定插件(它定义了“wysiwyg”绑定以将textarea与tinymce编辑器关联)。一切正常,除了我一直试图在TinyMCE控件中进行不引人注目的验证,但没有成功。正如您将看到的,我已经应用了这里和google中的一些建议解决方案,但没有一个有效 TinyMCE(也是TinyMCE jquery)版本是4.0.26 该守则涉及的部分如下: .CS(仅与TinyMCE控件关联的属性) “Loc”前缀属性继承自Requ

我正在使用MVC4和knockoutjs(带有映射插件)以及tinymce的绑定插件(它定义了“wysiwyg”绑定以将textarea与tinymce编辑器关联)。一切正常,除了我一直试图在TinyMCE控件中进行不引人注目的验证,但没有成功。正如您将看到的,我已经应用了这里和google中的一些建议解决方案,但没有一个有效

TinyMCE(也是TinyMCE jquery)版本是4.0.26

该守则涉及的部分如下:

.CS(仅与TinyMCE控件关联的属性)

“Loc”前缀属性继承自RequiredAttribute和DisplayNameAttribute数据注释类,用于从数据库检索本地化文本。它们工作得很好,因此假设它们是常规的必需属性和DisplayName属性。还有其他类似的属性:Text_es、Text_de等,它们应该有一组类似的属性,但现在我只在Text_en中设置所需的位置,直到问题解决为止

.CSHTML:

我还尝试在setDefaults行之后添加,同样没有结果:

frm.validate({
    rules: {
        Text_en:
        {
            required: true
        }
    }});

还有其他建议吗?我这里有什么问题吗?

它终于起作用了。多亏了@marathonman,我重新检查了该网站的帖子(之前,被接受的帖子是我已经做过的事情的来源),但这次我也查看了Brian Surowiec的帖子(当我有足够的积分可以投票时,我会把这两篇帖子投上去)而遵循他的建议,让文本区域在屏幕外显示,正是这项工作得以成功的原因。所以我补充了他所做的:

var offCss = { position: 'absolute', height: 0, width: 0, top: -100 };
$('#Text_en').css(offCss);
$('#Text_es').css(offCss);
...//and the same for the others

//after that called show() for them
$('#Text_en').show();
$('#Text_es').show();
...//and so on

就这些。顺便说一句:在我发布的其他代码中,我以前尝试过的frm.validate代码根本不需要,其他所有代码都保留了。

它解决了我的问题,谢谢。我已经查过了。从那篇被接受的文章中,我得到了上面提到的几乎所有东西。我终于可以让它工作了,但实现了下一个(Brian Surowiec的):让文本区域显示在屏幕外。我将用它创建一个回复帖子
$(function()
{
...
    var mapping = 
    {
        create: function(options)
        {
            var vm = ko.mapping.fromJS(options.data);
            ...
            ...
            vm.acceptDataEdit = function() //this is associated with the click event "Save" button in the form
            {
                tinymce.triggerSave(); //Almost every search on google says it solves the problem... Well, here it doesn't
                var ok = frm.valid(); //Validation works for other fields but not for the tinymce
                if (ok)
                {
                    ...//posts the data
                }
                return false;
            }

            ko.editable(vm);// ko.editable(this);
            return vm;
        }
    }

        ko.bindingHandlers['wysiwyg'].defaults =
    {

    theme: "modern",
    plugins: [
         "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
         "searchreplace  visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
         "table directionality emoticons template paste textcolor"
    ],
    forced_root_block : false,
    force_br_newlines : true,
    force_p_newlines : false,
    content_css: "css/content.css",
    toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l      ink image | print preview media fullpage | forecolor backcolor emoticons", 
    style_formats: [
         {title: 'Bold text', inline: 'b'},
         {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
         {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
         {title: 'Example 1', inline: 'span', classes: 'example1'},
         {title: 'Example 2', inline: 'span', classes: 'example2'},
         {title: 'Table styles'},
         {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ]
    };

    var viewModel = ko.mapping.fromJS(vData, mapping);
    ko.applyBindings(viewModel);

    $.validator.setDefaults({ ignore: '' }); // again, this is supposed to make the validator process the hidden text areas, but nothing happens

});
frm.validate({
    rules: {
        Text_en:
        {
            required: true
        }
    }});
var offCss = { position: 'absolute', height: 0, width: 0, top: -100 };
$('#Text_en').css(offCss);
$('#Text_es').css(offCss);
...//and the same for the others

//after that called show() for them
$('#Text_en').show();
$('#Text_es').show();
...//and so on