3

我有一个小问题。我正在使用 MVC 4 和“jQuery Validation Plugin 1.11.1”。

我在脚本部分插入自定义验证,如下所示:

jQuery.validator.addMethod("nameExist", function (value, element, param) {
            var notError = true;
            if (value == 'Hello')
            {
                 notError = false;
            }
            return notError;
        }, 'The name exists');

并创建具有新验证的类

jQuery.validator.addClassRules("nameExistErrClass", { nameExist: true });

然后在 html 部分执行以下操作:

@using (Html.BeginForm(MVC.Home.CopyData(), FormMethod.Post, new { id = "copyForm" }))
{

...

@Html.TextBox("newName", string.Empty, new { type = "text", @class = "nameExistErrClass"})
<span class="field-validation-valid" data-valmsg-for="newName" data-valmsg-replace="true"></span>

...

}

提交带有文本“Hello”的表单后,看起来验证正在工作,但错误消息是

警告:没有为 newName 定义消息

如何显示消息“名称存在”?

Ps 如果我添加属性

必需的=“必需的”

对于元素'newName',一切都很好,消息取自默认消息。

4

1 回答 1

-1

现在我知道了!对不起所有的混乱。JavaScript 部分运行良好。问题是这样的过载Html.BeginForm(String, FormMethod, Object)并不存在。请告诉我您尝试做什么,以便我可以给您正确的建议。我什至不明白这MVC.Home.CopyData()部分。你能告诉我更多关于这方面的信息吗?我认为您可能会为此选择错误的方法。

我希望这会对你有所帮助!

于 2013-09-24T21:47:22.887 回答