0

我的应用程序中的验证几乎没有问题。

我使用metro ui css,我想将metro ui中的验证与表单提交时来自数据注释的消息连接起来。

在我的模型中,我有带有属性 [必需] 的字段名称:

[Required(ErrorMessageResourceName = "Error", ErrorMessageResourceType = typeof(Resources.Common.Required))]
[StringLength(50, MinimumLength = 3)]
public string Name { get; set; }

在视图中,我创建了验证表单并输入:

    @using (Html.BeginForm("AddCalendar", "Admin", FormMethod.Post, new { data_role = "validator", data_on_submit = "formSubmit", data_hint_mode = "hint", data_hint_easing = "easeOutBounce" }))
       {
    @Html.AntiForgeryToken()
    <div class="row cells12">
        <div class="cell colspan2 padding-top05">
            @Resources.Models.Calendars.Name
        </div>
        <div class="cell colspan3 input-control text" data-role="input">
            @Html.TextBoxFor(m => m.Name, new { type = "text", maxlength = 50, required = "required", data_validate_func = "required", data_validate_hint = String.Format("{0}", Html.ValidationMessageFor(x => x.Name)), data_validate_hint_position = "right" })
            <span class="input-state-error mif-warning"></span>
            <span class="input-state-success mif-checkmark"></span>
        </div>
        <div class="cell no-margin">
            <div class="no-display too-short mif-notification fg-red cursor-pointer padding-left10 padding-top10 place-left"
                 data-role="hint" data-hint="@Resources.Common.Required.Error" data-hint-position="right"
                 data-hint-background="bg-red" data-hint-color="fg-white">
            </div>
        </div>
        <div class="cell colspan5">
            <h4 class="text-light no-margin-top">@Resources.Views.Admin.AddCalendar.WorkingDays</h4>
            <hr>
        </div>
    </div>

        <div class="row cells12">
            <div class="cell colspan5"></div>
            <div class="cell no-margin"></div>
            <div class="cell offset">
                <input type="submit" class="button" value="@Resources.Common.Buttons.Save">
            </div>
        </div>
}

当我在空名称字段上单击我的表单提交时,我有空提示。我想使用来自数据注释的消息添加到我的提示中。我能怎么做 ?

4

0 回答 0