Html.ValidationMessage文本颜色 [英] Html.ValidationMessageFor Text Color

查看:637
本文介绍了Html.ValidationMessage文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能是一个简单的问题,但我似乎找不到答案。



使用MVC 2我有一系列的Html.ValidationFor控件。我想为文本分配一个CSS类,而且似乎不能这么做。

 <%= Html.TextBoxFor => Model.Chest,new {@class =textBoxMeasure})%> 
<%= Html.ValidationMessageFor(Model => Model.Chest)%>

如果我尝试与textbox相同的方法,我得到错误,因为它需要一个字符串,当我把一个

解决方案

有一个变量,它将htmlAttributes作为第三个参数(第二个是应该显示的消息,或者您可以使用null作为默认验证消息)

  Html.ValidationMessageFor(
Model => Model.Chest,
请输入值,
new {@class =redText})

有关详细信息,请参阅 http://msdn.microsoft.com/en-us/library/ee721293%28v=vs.98%29.aspx


Probably a simple question, but i cant seem to find the answer.

using MVC 2 i have a series of Html.ValidationFor controls. I want to assign a CSS class to the text and cant seem to do it.

<%= Html.TextBoxFor(Model => Model.Chest, new { @class = "textBoxMeasure" })%>
<%= Html.ValidationMessageFor(Model => Model.Chest) %>

if i try the same method as textboxfor i get errors because it requires a string, when i put a string in it still wont work!

thanks

解决方案

There's a variant that takes htmlAttributes as the third argument (the second is the message that should be displayed, or you can use null for the default validation message)

Html.ValidationMessageFor(
        Model => Model.Chest, 
        "Please enter a value", 
        new { @class = "redText" })

For more info see http://msdn.microsoft.com/en-us/library/ee721293%28v=vs.98%29.aspx

这篇关于Html.ValidationMessage文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆