html - 验证错误时 ASP.NET MVC5 文本区域未以红色标出

标签 html css asp.net asp.net-mvc twitter-bootstrap

我将 ASP.NET MVC5 与 Bootstrap 一起使用,并在联系表单的 Razor View 中具有以下内容...

@using (Html.BeginForm("Contact", "Home", FormMethod.Post, new {role = "form"})) {
<div class="form-group">
@Html.LabelFor(model => model.theirname)
@Html.TextBoxFor(model => model.theirname, new {@class = "form-control", placeholder = "Enter your name"})
<div>@Html.ValidationMessageFor(model => model.theirname, "You must enter your name")</div>
  @Html.LabelFor(model => model.theiremail)
  @Html.TextBoxFor(model => model.theiremail, new {@class = "form-control", placeholder = "Enter your email"})
  <div>@Html.ValidationMessageFor(model => model.theiremail, "You must enter your email address")</div>
  @Html.LabelFor(model => model.message)
  @Html.TextAreaFor(model => model.message, new {@class = "form-control", placeholder = "Enter message", cols = 40, rows = 5})
  <div>@Html.ValidationMessageFor(model => model.message, "You must enter a message")</div>
  <input type="checkbox" id="copytome" name="copytome" checked="@Model.copytome" /> <label for="copytome">Send me a copy of the message</label>
  <div><input type="submit" value="Send" class="btn btn-default" /></div>
</div>
}

如果用户在没有填写姓名或电子邮件地址的情况下单击提交按钮,则会正确显示验证消息,并且文本框会以红色标出。

但是,尽管显示了验证消息,但文本区域并未显示轮廓... enter image description here

这是生成的 HTML...

<form action="/Home/Contact" method="post" role="form">
<div class="form-group">
<label for="theirname">Your name</label>
<input class="input-validation-error form-control" data-val="true" data-val-required="The Your name field is required." id="theirname" name="theirname" placeholder="Enter your name" type="text" value="" />
<div><span class="field-validation-error" data-valmsg-for="theirname" data-valmsg-replace="false">You must enter your name</span></div>
<label for="theiremail">Your email</label>
<input class="input-validation-error form-control" data-val="true" data-val-required="The Your email field is required." id="theiremail" name="theiremail" placeholder="Enter your email" type="text" value="" />
<div><span class="field-validation-error" data-valmsg-for="theiremail" data-valmsg-replace="false">You must enter your email address</span></div>
<label for="message">Message</label>
<textarea class="input-validation-error form-control" cols="40" data-val="true" data-val-required="The Message field is required." id="message" name="message" placeholder="Enter message" rows="5">
</textarea>
<div><span class="field-validation-error" data-valmsg-for="message" data-valmsg-replace="false">You must enter a message</span></div>
<input type="checkbox" id="copytome" name="copytome" /> <label for="copytome">Send me a copy of the message</label>
<div><input type="submit" value="Send" class="btn btn-default" /></div>
</div>
</form>

有人知道为什么文本区域没有用红色标出吗?

最佳答案

大概 bootstrap 不包含无效文本区域元素的样式规则。您可以通过将以下内容添加到您的样式表来修复它:

 textarea.input-validation-error {
      border-color: red;
 }

关于html - 验证错误时 ASP.NET MVC5 文本区域未以红色标出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25039888/

相关文章:

asp.net - 如何避免 System.Xml.Linq.XElement 转义 HTML 内容?

css - 扩展Grid系统中Div的背景色

javascript - CSS 网格系统或媒体查询

css - React - 无法使用 CSS 模块设置 React 路由器导航链接的事件状态样式

html - 设置内联 block div 以忽略换行符

c# - asp.net多线程页面

Javascript - 在水果列表下拉列表中添加一次橙色

jquery - 居中对齐 div 内容

css - 具有响应式设计的 CSS 中的@media 查询问题

c# - asp.net 在更改下拉列表时使用 javascript 填充下拉列表