我有一个表格:
using (Html.BeginForm())
{
@Html.TextBoxFor(x => x.Name, new { @class = "span8" })
}
模型:
[Required]
[RegularExpressionAttribute("regex")]
public string Name { get; set; }
控制器:
[HttpPost]
public ActionResult Index(MyModel model)
{
return View(model);
}
如果禁用 javascript,如何显示错误消息并更改名称文本框的 css 样式?
据我了解:
@Html.ValidationMessageFor(x => x.Name, "error text", new { style = "backgroundcolor: red;"})
不行吗?
在输出 HTML 中,我可以看到生成的 span,ValidatorMessageFor
但它有一个btn-group
隐藏此标签的 css 类。