使用 xval 客户端验证表单

发布于 2024-08-29 19:22:46 字数 802 浏览 5 评论 0原文

我正在使用 ASP.NET MVC2 并验证我使用 xVal 的表单。看起来服务器端验证工作正常,但客户端验证不起作用或至少不显示。

我使用的代码如下所示:

<% using (Html.BeginForm()) {%>
    div class="label"><label for="EmailAddress">Email Address</label></div>
                    <div class="field">
                        <%= Html.TextBox(Prefix + ".EmailAddress")%>
                        <%= Html.ValidationMessage(Prefix + ".EmailAddress")%>
                    </div>
<%}%>
<%= Html.ClientSideValidation<Customer>(Prefix)%>

当我删除前缀时,它工作正常。但是当我删除它时,只有服务器端验证有效。

在这一侧的 xVal 上搜索,我发现这篇文章看起来有点像同样的问题: 将 xval 与包含句点的字段结合使用 但这里还没有答案。

预先感谢您的帮助。

I am using ASP.NET MVC2 and to validate the forms i use xVal. It seems like the server side validation works fine, but the client side validation doesnt work or atleast doesn't show up.

The code i use looks like this:

<% using (Html.BeginForm()) {%>
    div class="label"><label for="EmailAddress">Email Address</label></div>
                    <div class="field">
                        <%= Html.TextBox(Prefix + ".EmailAddress")%>
                        <%= Html.ValidationMessage(Prefix + ".EmailAddress")%>
                    </div>
<%}%>
<%= Html.ClientSideValidation<Customer>(Prefix)%>

When i remove the prefix it works fine. But when i remove it only the server side validation works.

Searching on xVal on this side i found this post that looks a bit like the same problem:
Using xval with fields containing periods
But no answers here (yet).

Thanks in advance for the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻泪 2024-09-05 19:22:46

用以下代码解决了它:

<% using (Html.BeginForm("ActionName", "Controller")) {%>
    div class="label"><label for="EmailAddress">Email Address</label></div>
                    <div class="field">
                        <%= Html.TextBox("EmailAddress")%>
                        <%= Html.ValidationMessage("EmailAddress")%>
                    </div>
<%}%>
<%= Html.ClientSideValidation<Customer>()%>

Solved it with the following code:

<% using (Html.BeginForm("ActionName", "Controller")) {%>
    div class="label"><label for="EmailAddress">Email Address</label></div>
                    <div class="field">
                        <%= Html.TextBox("EmailAddress")%>
                        <%= Html.ValidationMessage("EmailAddress")%>
                    </div>
<%}%>
<%= Html.ClientSideValidation<Customer>()%>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文