使用MVC 3应用程序.
我的模特儿
[required(ErrorMessage = "Role Name is required")] [RegularExpression(@"^[a-zA-Z ]+$",ErrorMessage = "Only alphabets and spaces allowed")] public string RoleName { get; set; }
<label for="name">RoleName</label> @Html.TextBoxFor(m => m.RoleName) @Html.ValidationMessageFor(m => m.RoleName,"some",new { @class = "immediate" })
But i could not see overloaded method like
@Html.ValidationMessageFor(m => m.RoleName,htmlAttributes) . if i
give some text,it is not showing my validaton message entered in
model. It always shows that some text only.
任何修复这个?
解决方法
你应该能够简单地传入null …
@ Html.ValidationMessageFor(m => m.RoleName,null,new {@class =“immediate”})