0
我想在验证失败时显示图像而不是文本,但ValidationMessageFor对我的'validationMessage'进行编码。 我想使用普通的img标签声明指定validationMessage 我该怎么做?MVC ValidationMessageFor
谢谢
我想在验证失败时显示图像而不是文本,但ValidationMessageFor对我的'validationMessage'进行编码。 我想使用普通的img标签声明指定validationMessage 我该怎么做?MVC ValidationMessageFor
谢谢
您将需要创建自己的HTMLHelper。
喜欢的东西:
public static MvcHtmlString ValidationImage(this HtmlHelper htmlHelper)
{
if (!htmlHelper.ViewData.ModelState.IsValid)
{
//todo: strip out the information you need from the model and return <img/> tag(s).
}
return null;
}
你可以声明包含图像的常量字符串在HTML格式,如:在查看操作
const string ERROR_IMAGE = "<img src=\"...\" alt=\"\" />";
你可以做这样的事情:
if(Something is Ine error)
ModelState.AddModelError(Something, ERROR_IMAGE);
你的意思是像''? – 2011-01-27 13:21:48
编辑...对不起 – TiagoDias 2011-01-27 13:27:04