嗨,这是我的模型代码中的RegularExpression
[Required]
[StringLength(127)]
[RegularExpression("^[a-zA-Z]+$", ErrorMessage = "Enter only alphabets for First Name")]
public string FirstName { get; set; } //First Name should only use Alphabets
这是/home/index.aspx页面中的验证
<% using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @id = "AudienceRequest" }))
{ %>
<%= Html.ValidationSummary(true, "To request tickets, please complete the required (*) fields below and click Submit") %>
<div>
<label>First Name
<%= Html.ValidationMessageFor(x => x.FirstName, "*") %></label>
<%= Html.TextBoxFor(x => x.FirstName) %>
目前,验证部分有效。如果我输入BOB333,它将不会提交表格。但显示的消息是错误的。它仍然显示“要请求票证,请填写下面所需的(*)字段,然后单击”提交“,而不是”仅输入名字的字母“
请告知。
由于
答案 0 :(得分:3)
您需要更改
<%= Html.ValidationSummary(true, "To request tickets, please complete the required (*) fields below and click Submit") %>
到
<%= Html.ValidationSummary(false, "To request tickets, please complete the required (*) fields below and click Submit") %>
布尔标志是“排除属性错误” - 请参阅MSDN