客户端验证不在共享主机上工作,但在调试时有效

时间:2013-03-30 06:01:26

标签: c# jquery asp.net-mvc-4 jquery-validate asp.net-mvc-validation

我在模型类中有以下属性:

[MaxLength(9), Required, DisplayName("Social security number")]
[RegularExpression(@"\d{3}-\d\d-\d{4}", ErrorMessage = "Invalid social security number")]
public string SocialSecurityNumber { get; set; }

Markup(Razor):

@Html.TextBoxFor(model => model.SocialSecurityNumber, new { id = "ssn" })
@Html.ValidationMessageFor(model => model.SocialSecurityNumber)

生成的HTML代码为:

<input data-val="true" data-val-regex="Invalid social security number" data-val-regex-pattern="\d{3}-\d\d-\d{4}" data-val-required="The Social security number field is required." id="ssn" name="SocialSecurityNumber" type="text" value="">
<span class="field-validation-valid" data-valmsg-for="SocialSecurityNumber" data-valmsg-replace="true"></span>

但是,如果我只键入一个数字并单击已发布的共享主机站点上的另一个输入框,则不会显示错误消息。使用Visual Studio 2012(chrome浏览器)进行调试时,将显示错误消息Invalid social security number。什么可能导致这个问题?

更新 在我的本地PC(Visual Studio调试)上生成的html代码是。

<input data-val="true" data-val-regex="Invalid social security number" data-val-regex-pattern="\d{3}-\d\d-\d{4}" data-val-required="The Social security number field is required." id="ssn" name="SocialSecurityNumber" type="text" value="" class="input-validation-error">
<span class="field-validation-error" data-valmsg-for="SocialSecurityNumber" data-valmsg-replace="true"><span for="ssn" class="" style="">Invalid social security number</span></span>

我本地电脑的html代码似乎有class="input-validation-error",主机网站上不存在?

0 个答案:

没有答案