简体   繁体   English

Kendo UI Grid不支持远程MVC验证吗?

[英]Kendo UI Grid is not Supported Remote MVC Validation?

I have put mvc remote validation in model class and this remote validation method is calling which I have controller .It is perfectly working for mvc view but not working with kendo ui grid . 我将mvc远程验证放在模型类中,并且此远程验证方法正在调用我拥有控制器的方法。它完全适用于mvc视图,但不适用于kendo ui grid

Please help me if anyone know about this issue. 如果有人知道这个问题,请帮助我。

My model code is: 我的模型代码是:

[Required]
    [Remote("CheckDuplicateRoleName",
        "Role",
        AdditionalFields = "RoleId",
        ErrorMessage = "This Role Name already exists.")]
    public string RoleName { get; set; }

    }       

For mvc remote validation CheckDuplicateRoleName is method name which I had put in Role controller and RoleId is additional field .I want to display this errormessage in kendo popup for check duplicate rolename exist in database .But this controller method is not calling . 对于mvc远程验证, CheckDuplicateRoleName是我在Role controller输入的方法名称,而RoleId是其他字段。我想在errormessage弹出窗口中显示此errormessage ,以检查数据库中是否存在重复的Role controller名。但是此控制器方法未调用。

I have found solution for remote mvc validation 我找到了远程MVC验证的解决方案

 (function ($, kendo) {
        $.extend(true, kendo.ui.validator, {
            rules: {
                mvcremotevalidation: function (input) {
                    if (input.is("[data-val-remote]") && input.val() != "") {
                        var remoteURL = input.attr("data-val-remote-url");
                        var valid;

                        $.ajax({
                            async: false,
                            url: remoteURL,
                            type: "GET",
                            dataType: "json",
                            data: validationData(input, this.element),
                            success: function (result) {
                                valid = result;
                            },
                            error: function () {
                                valid = false;
                            }
                        });

                        return valid;
                    }

                    return true;
                }
            },
            messages: {
                mvcremotevalidation: function (input) {
                    return input.attr("data-val-remote");
                }
            }
        });

        function validationData(input, context) {
            var fields = input.attr("data-val-remote-additionalFields").split(",");
            var name = input.prop("name");
            var prefix = name.substr(0, name.lastIndexOf(".") + 1);
            var fieldName;
            var data = {};
            for (var i = 0; i < fields.length; i++) {
                fieldName = fields[i].replace("*.", prefix);
                data[fieldName] = $("[name='" + fieldName + "']", context).val();
            }
            return data;
        }
    })(jQuery, kendo);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM