本文介绍了验证失败时TextBox周围的红色边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用ASP.NET MVC 2.

I am using ASP.NET MVC 2.

Html.DropDownListFor和Html.TextAreaFor在验证失败时会自动显示红色边框.

Html.DropDownListFor and Html.TextAreaFor automatically get red borders when the validation fails.

当验证失败时,如何使TextBox的四个边框(使用Html.TextBoxFor)变为红色?

How to make the four borders of a TextBox (using Html.TextBoxFor) red when it fails validation?

例如,我有一个必需的TextBox,并且当用户提交表单时未在文本框中指定值时,我希望文本框具有红色边框.

For example, I have a TextBox that is required and when the user submits the form without specifying a value in the textbox, I want the textbox to have red borders.

推荐答案

当对模型属性的验证失败时,它将在html输入中添加一个类.验证失败时,请查看呈现的html(使用视图源或firebug),并检出用于输入的类*.然后编辑CSS,以包含验证失败的样式.

When validation fails for a model property - it'll add a class to the input in the html. Have a look at the rendered html when the validation fails (using view source or firebug) and check out the class for your input*. Then edit your css to include a style for the failed validation.

例如在我的项目中,我有:

E.g. In my project I have:

input.input-validation-error,
textarea.input-validation-error,
select.input-validation-error
{
    background: #FEF1EC;
    border: 1px solid #CD0A0A;
}

HTH,
查尔斯

HTHs,
Charles

*我很确定ASP.NET MVC默认情况下会添加类 input-validation-error .

* I'm pretty sure ASP.NET MVC add the class input-validation-error by default.

这篇关于验证失败时TextBox周围的红色边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:54