1

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

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

标记(剃刀):

@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>

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

更新: 在我的本地 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>

似乎我的本地 PC 的 html 代码class="input-validation-error"在主机站点上不存在?

4

0 回答 0