Asp.net MVC 3 RC - 剃刀ValidationMessageFor CUSTOMMESSAGE和ClientSideValidation问题 [英] Asp.net MVC 3 RC - Razor ValidationMessageFor CustomMessage and ClientSideValidation Problem

查看:111
本文介绍了Asp.net MVC 3 RC - 剃刀ValidationMessageFor CUSTOMMESSAGE和ClientSideValidation问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.Net MVC 3 RC,剃刀

ASP.Net MVC 3 RC, Razor

遇到一些意外的行为,当我尝试使用自定义消息,并使用客户端验证。问题是,它始终显示,即使没有错误自定义消息。

Experiencing some unexpected behavior when I try to use a custom message and using client side validation. The problem is it always displays the custom message even though there is no error.

所以说我有那里的名​​字被设置为需要客户端模式。如果我有以下code验证消息不显示,直到我点击提交预期其中工程。

So say I have a Client Model where the FirstName is set as Required. If I have the following code the validation message is not displayed until I click on Submit which works as expected.

@Html.EditorFor(model => model.Client.FirstName) @Html.ValidationMessageFor(model => model.Client.FirstName)

但现在说我要自定义的验证消息使用星号,像这样:

But now say I want to customize the validation message to use an asterisk like so:

@Html.EditorFor(model => model.Client.FirstName) @Html.ValidationMessageFor(model => model.Client.FirstName, "*")

现在甚至在我点击提交按钮,总有字段旁边的星号。

Now even before I click on the submit button, there is always an asterisk next to the field.

预期的行为是,它会显示星号时,有一个验证错误。

The expected behavior is that it would show the asterisk when there is a validation error.

感谢您的帮助。

推荐答案

我发现这个问题,需要以下的CSS:

I found the problem, the following CSS is needed:

.field-validation-valid
{
    display: none;
}
.validation-summary-valid
{
    display: none;
}

沿着我重构这些类某处得到取出。他们在那里默认情况下,当你开始一个新的MVC 3项目。希望可以帮助别人的未来!

Somewhere along my refactoring those classes got taken out. They are in there by default when you start a new MVC 3 project. Hope that helps someone in the future!

这篇关于Asp.net MVC 3 RC - 剃刀ValidationMessageFor CUSTOMMESSAGE和ClientSideValidation问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆