Html.ValidationMessageFor错误定位正好位于文本框下方

时间:2017-09-29 14:55:32

标签: css asp.net-mvc

我无法按照我想要的方式定位错误消息,因此感到非常沮丧。

当前位置:

enter image description here

由于文本框和错误消息之间存在间距。我希望它被删除

这是我的代码:

 @using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
        {
            @Html.AntiForgeryToken()
            <div>
                @Html.TextBoxFor(m => m.FullName, new { @class = "form-control", placeholder = Html.DisplayNameFor(n => n.FullName) })
                @Html.ValidationMessageFor(m => m.FullName, "", new { @class = "error" })
            </div>
            <div>
                @Html.TextBoxFor(m => m.UserName, new { @class = "form-control", placeholder = Html.DisplayNameFor(n => n.UserName) })
                @Html.ValidationMessageFor(m => m.UserName, "", new { @class = "error" })
            </div>

CSS错误类

 .error {
    color: red;
    font-size: 16px;
}

实际HTML代码

<form action="/Account/Register" class="form-horizontal" method="post" role="form"><input name="__RequestVerificationToken" type="hidden" value="v8LXyFpGahDys5MbQkFWWvHJiadmmK8lV-B0y5a3GngLOrJnZrQFP5jAYhvRf-bN0ds7yIcO24I0ydxj0FTkahVYg4kT8vazwxCuY4juuyM1" />                <div>
                <input class="form-control" data-val="true" data-val-length="The Full Name must be at least 3 characters long." data-val-length-max="35" data-val-length-min="3" data-val-required="The Full Name field is required." id="FullName" name="FullName" placeholder="Full Name" type="text" value="" />
                <span class="field-validation-valid error" data-valmsg-for="FullName" data-valmsg-replace="true"></span>
            </div>
            <div>
                <input class="form-control" data-val="true" data-val-required="The User name field is required." id="UserName" name="UserName" placeholder="User name" type="text" value="" />
                <span class="field-validation-valid error" data-valmsg-for="UserName" data-valmsg-replace="true"></span>
            </div>
            <div>
                <input class="form-control" data-val="true" data-val-email="The Email field is not a valid e-mail address." data-val-required="The Email field is required." id="Email" name="Email" placeholder="Email" type="text" value="" />
                <span class="field-validation-valid error" data-valmsg-for="Email" data-valmsg-replace="true"></span>
            </div>

0 个答案:

没有答案