将Metro ui css中的验证表单与MVC5中的数据注释相关联

时间:2016-09-01 07:34:35

标签: asp.net asp.net-mvc validation metro-ui-css

我的应用程序验证没什么问题。

我使用metro ui css,我想在metro ui中使用来自表单提交的Data Annotations的消息进行连接验证。

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

[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>
}

当我在空名称字段上单击我的表单提交时,我有空提示。我想使用Data Annotations中的消息添加到我的提示中。我该怎么办?

0 个答案:

没有答案