1

嗨,这是我的模型代码中的正则表达式

    [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,它将不会提交表单。但显示的消息是错误的。它仍然显示“要申请门票,请填写下面的必填 (*) 字段并单击提交”,而不是“仅输入名字的字母”

请指教。

谢谢

4

1 回答 1

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

于 2013-08-14T22:42:09.983 回答