型号类:
public class MyClass
{
......
[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)
在 Visual Studio 2012/Chrome 中运行时生成的代码。
<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>
发布到共享主机后生成的代码
<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>
为什么通过 VS 运行的站点生成的 html 代码更多?( class="input-validation-error">
等)