首页 > 解决方案 > 样式化 ASP.NET MVC 验证错误不起作用?

问题描述

我已经设置了 .field-validation-error 的样式,如图所示

.field-validation-error{ color: red; font-weight: bold; }

还有 .input-validation-error

.input-validation-error{ border: 2px solid red; }

但不幸的是,我的验证错误和输入字段与以前的颜色相同。

这是html代码

@model MovieApp.ViewModel.CustomerFormViewModel
@{
    ViewBag.Title = "New";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<br />
<h1>New customer</h1>
@using (Html.BeginForm("Save", "Customers"))
{
    <div class="form-group">
        @Html.LabelFor(c => c.Customer.FirstName)
        @Html.TextBoxFor(c => c.Customer.FirstName, new { @class = "form-control" })
        @Html.ValidationMessageFor(c => c.Customer.FirstName)
    </div>
    <div class="form-group">
        @Html.LabelFor(c => c.Customer.LastName)
        @Html.TextBoxFor(c => c.Customer.LastName, new { @class = "form-control" })
        @Html.ValidationMessageFor(c => c.Customer.LastName)
    </div>
    <div class="form-group">
        @Html.LabelFor(c => c.Customer.BirthDate)
        @Html.TextBoxFor(c => c.Customer.BirthDate, new { @class = "form-control" })
    </div>
    <div class="form-group">
        @Html.LabelFor(c => c.Customer.MembershipTypeId)
        @Html.DropDownListFor(c => c.Customer.MembershipTypeId
        ,new SelectList(Model.MembershipTypes,"Id","Name")
        ,"Select Membership Type"
        ,new { @class = "form-control" })
        @Html.ValidationMessageFor(c => c.Customer.MembershipTypeId)
    </div>

    <div class="checkbox">
        <label>
            @Html.CheckBoxFor(c => c.Customer.IsSubscribedToNewsLetter) Subscribed to newsletter?
        </label>
    </div>

    @Html.HiddenFor(c => c.Customer.Id)

    <button type="submit" class="btn btn-primary">SAVE</button>
}

标签: asp.netasp.net-mvc

解决方案


推荐阅读